Skip to content

Instantly share code, notes, and snippets.

@KaineLabs
Last active February 13, 2022 23:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KaineLabs/8d23610479224cb95c9bda73d16c3667 to your computer and use it in GitHub Desktop.
Save KaineLabs/8d23610479224cb95c9bda73d16c3667 to your computer and use it in GitHub Desktop.
Insert Ads Between Activity Posts
<?php
// Set Ads Counter.
function yzc_set_global_ads_counter() {
global $yzc_ads_count;
$yzc_ads_count = 1;
}
add_action( 'bp_before_activity_loop', 'yzc_set_global_ads_counter' );
// Insert Ads Between each 2 posts.
function yzc_add_ads_between_activity_posts() {
global $yzc_ads_count;
if ( $yzc_ads_count == 1 ) {
$yzc_ads_count++;
return;
}
if ( $yzc_ads_count%2 == 1 ) {
?>
<li class="ad">
<div class="activity-content">
<!-- Ad code here -->
</div>
</li>
<?php
}
$yzc_ads_count++;
}
add_action( 'bp_before_activity_entry', 'yzc_add_ads_between_activity_posts' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment