Tagged: ads in buddypress, code snippets
i use this code my modemlooper `function custom_markup_before_every_fifth_activity() {
global $activities_template;$item_5 = $activities_template->activities[4];
if ( $item_5->id === $activities_template->activity->id ) {
echo ‘adsense code here’;
}}
};
add_action( ‘bp_before_activity_entry’, ‘custom_markup_before_every_fifth_activity’ );`
it show ads after every 5 activity but has a little problem when I went from “all members” to “friends” and the activity feed didn’t load. I have to refresh the page to get it to load.Hi Lucas,
Welcome to BuddyDev and thank you for asking the question.You don’t need the above code, There is a simple and better way to do it. Please allow me to write a blog post and link it here.
Since this seems to be beneficial for many people, I am going to write a post with details and link here.
Will be linking in next 24 hours.Thank you
BrajeshThank you.
Here we go
https://buddydev.com/inject-content-into-buddypress-activity-stream-after-a-certain-number-of-activities/Best regards
BrajeshHi Lucas,
Thank you.
Can you please share the code and the answer to following question.1. Is it happening in all cases if you use adsense?
2. or is it only happening on loading new activities(load more/filters)Did you inject the adsense library code in header before adding the ads snippet?
Regards
Brajeshthanks for the reply
well i customize a bit but i have also tried it with the original code you gave but problem still exist. well the problem is that when you are on site wide activity stream when you click on my friend activity it shows a blank page and until you refresh
ok i am sharing the code i am using.function buddydev_inject_content_after_n_activities() { static $current_activity_index = 1; // change $n to the correct number of activities. $n = 5; // After how many activities you want to inject content. if ( !is_user_logged_in()){ //i added it to show ads only to non-logged in user if ( $current_activity_index % $n === 0 ) { ?> <div class="activity-avatar"> <div class="names"style="color:#c92e2e;">Sponsored</div> <div class="nices-name">@sponsored</div> </div> <div class="activity-content"> <div class="ads"><script async adsense code //this the adsense script </script></div> </div><?php // show the activity injected content. }} // increment the current index. $current_activity_index ++; } add_action( 'bp_after_activity_entry', 'buddydev_inject_content_after_n_activities' );
Hi Lucas,
I am guessing it is only happening with adsense.
Adsense does not seem to be supported in content loaded via ajax. You will most probably need to do extra works for ithttps://support.google.com/admanager/answer/2694377
Regards
Brajesh
You must be logged in to reply to this topic.