Integrating Adsense into WordPress
- Posted by B Jones on November 26th, 2005 - Comment on this Post »
As some of you may have noticed, I recently integrated some advertising into the main page of seologs. I had to do a little bit of searching to figure out exactly where the ads should go. Getting ads to show up on the index page was a little bit tricky, so I’m going to show you what to do.
Main Template
To add adwords, or any other ads to the index page of your WordPress blog, you must edit the Main Template. If you are completely unfamiliar with PHP, you may want to find someone who is familiar to help you. In any case, you should always BACKUP your data. So..
1. Start by making a copy of your Main Template in wordpress. (if you are a php expert or really brave, you can skip this)
- Go into the admin pannel >Presentation > Theme Editor > Main Template , and either copy and paste the original into a text editor and save it, or you can use your ftp to go into which ever theme you are using and just back up the whole thing.
2. Look for this line < ?php if (have_posts()) : ?>
- Add this line < ?php $postnum = 1; ?>
3. Scroll down and look for somthing about comments followed by < ?php endwhile; ?>
-just before < ?php endwhile; ?>, add this
< ?php if ($postnum == 1 || $postnum == 3 || $postnum == 5 || $postnum == 7 || $postnum == 9 ) { ?>
< ?php }
$postnum++; ?>
As you can see, whenever postnum is 1,3,5,7, or 9 , Wordpress will show the AdWords ads. If you only want the ads shown once, it would look somthing like
… if ($postnum == 1 ) …
If you want ads after every post, just take out the whole if clause, but you probably don’t want to do that, because the more ads you have on a page, the less they will pay.
If you enjoyed this post, make sure you subscribe to my RSS feed!

Leave a Comment