Home
 

How to Place Google Ads or Any Other Code in BuddyPress Activity Stream Pages


I recently added the BuddyPress plugin to my daughter’s site (diaryforteens.com). I’m constantly impressed with all of the extraordinary plugins and add-ons for WordPress. Shortly after adding BuddyPress to her site, people started joining and using this super cool feature. Naturally the AdSense wheels started turning. It became evident that there was no plugin to inject ads to the BuddyPress activity stream, and so here we are.

Check out DiaryForTeens.com Today!

Ok, so let me start by saying I’m not a WordPress guru, not do a write plugins and I caution those of you who don’t want to venture into unknown territory. Secondly, this is probably something that would need to be fixed after applying any BuddyPress update as the file could be overwritten with a newer version. Ok if you’re still with me and want to place ads in your BuddyPress activity streams then have a look at the simple directions below.



Use your favorite FTP program or simply access your hosting directory by using the built in FTP functionality of windows folder explorer (yes you can FTP right out of your My Computer). Navigate to this folder within your WordPress installation > wp-content > plugins > buddypress > bp-themes > bp-default > activity. Download the entry.php file and make a copy of it somewhere. Open the original with your favorite text editor and search for a line that looks like this.
<?php bp_activity_content_body() ?>
Right below this line we’re going start counting how many post are being displayed on the page. We’re going to assign this to a variable. You’re going to insert this line.
<?php $adcnt=$adcnt+1;?>
Easy stuff here right? Ok now we’re going to insert the ad code. I’m only placing two ads in the stream as I already have an ad on my sidebar. In this example I’m inserting the ads on the second post and the fourth post. Change these numbers to whatever you want.
<?php if ($adcnt=="2" or $adcnt=="4") echo '**PASTE YOUR ADSENSE CODE HERE**';?>
And that’s it, the quick and dirty way to inject a couple of ads into your activity streams on BuddyPress pages. The ads will show up in the site wide activity stream as well as on profile pages which are basically activity streams for specific users. Post your questions if you get stuck. WordPress gurus… I know this is not the “proper” way to do it, but that’s how I roll. Here is the shamelees plug to help increase my daughter’s revenue… check out DiaryForTeens.com today!!!

Bookmark and Share: