If you’re reading this post then you already realize that Thesis is quite possibly the best thing since, well, WordPress itself. I had wanted to be able to add my Adsense code to Thesis in such a way that my ads would display on every post, align left, with text wrapped around the ad. After a great deal of research and lots of tweaking I had finally found a Thesis hook to make this work. Here’s how you can modify your custom_functions.php file to add your Adsense code to every post on your blog.
First of all, I’m not a “coder” so I wanted to thank Adam over at adam.tv for posting the code I used as a “framework” for my Adsense hook. Secondly, please be sure to backup your custom_functions.php file before modifying it! Here is the code that I added to my custom_functions.php file so I can display Adsense ads on all of the posts pages in my blog;
Here’s a color coded explanation of which portions of this Thesis hook that you need to modify in order to change your Adsense placement.
Red - This line is used to prevent Adsense ads from appearing on certain pages that you specify. I for example didn’t want Adsense ads appearing right smack in the middle of my privacy policy as well as on some of my other static pages.
Green - This line specifies that all of my Adsense ads will be aligned to the left with text wrapped around them. You can of course modify this line to fit your needs.
Brown - This line “tells” Thesis to display my Adsense ad before every post i.e. under the post title and post image.
Final thoughts…
Remember that this code will add your Adsense ads to EVERY post page on your blog. You will need to ad your Adsense code to other parts of your site such as the header, widgets, footer, etc… using a different method. This method of placing Adsense ads using Thesis hooks worked for me, hopefully it will work for you too!
No related posts.
{ 9 comments… read them below or add one }
Finally, a code that actually works! Actually there are a lot of articles out there for the same purpose but yours is the first where margins around ads (so they don’t touch the text in the content) actually work! I deployed this in my blog although I modified it a bit to fit my needs.
Thanks Mike!
Thanks so much for this. I’m not even using ads, just custom HTML & PHP. But this is the only place I’ve found that articulates how to use the $post_count attribute to target specific posts’ hooks. A total lifesaver (or at least hairsaver, as I was pulling it out when the documentation said the attribute could be used but didn’t say *how*). Bookmarked!
doesnt work for me either, copied it and nothing happens.
Good deal! I’ve become quite fond of this little timesaver as well! Thanks for visiting CompuNoodle!
Great, it works for me. Thanks so much! Very useful indeed.
Good morning Nicole, I’ve now triple checked my code and… I found a discrepancy between my actual code and what I had posted in this article. Somehow, I had neglected to paste in the class attribute “adsense” which should have been specified as part of the div tag. The accuracy of the information posted on CompuNoodle is very important to me so I would much rather admit to a mistake as opposed to making excuses. Thanks to you an Richard for pointing this out, I hadn’t received any comments on this post thus far and had therefore assumed that all was well and good. Ctrl + V can be a dangerous thing, even in the hands of a 10+ year computer professional!
Richard – did you ever find a solution for this? I have the same problem….
Sorry to hear this, I actually use this on all of my sites and it works flawlessly. The one thing that comes to mind immediately is to make sure that you aren’t running an ad blocker, or if you are you need to make sure that you exempt your own domain. I did that by mistake when I first built this site… Oops
The other thing is to make sure that you give newly created Adsense ads up to 10 minutes to appear on your page. You also need to remember that you can only have a maximum of 3 ad units and 3 link units on each page. Have you made any other modifications to your custom functions file?
This doesn’t work for me. I’ve copied exactly into my custom_functions.php and the post pages just come up blank. I’m running on Thesis 1.8. Any ideas?