How to Add Google Ad Section Targeting in Thesis
Recently Matt Cutts gave a talk called Straight from Google: What You Need to Know at WordCamp San Francisco 2009. His talk revolved around why bloggers blog (money? fame? fun?) and how bloggers can improve their SEO. Jim Gaudet noted a couple lines of code from the presentation that are highly relevant to bloggers using Adsense to make money online. The two lines dictate where the unique content starts and ends on your page and target your ads to that content. It’s a handy way to have the Adsense algorithms display more relevant advertisements to your visitors.
While Jim created a handy plugin to insert the Adsense section code, Thesis users can insert these two lines quickly and easily by utilizing a custom function and hooking it in before and after the post content.
The Code
To do so, open up your custom_functions.php file. Then copy and paste the below code into the file, save, and you’re all set!
Scroll down for an explanation of what this code does.
function adsense_marker_start(){ echo '<!-- google_ad_section_start -->'; } add_action('thesis_hook_before_post_box', 'adsense_marker_start'); function adsense_marker_end(){ echo '<!-- google_ad_section_end -->'; } add_action('thesis_hook_after_post', 'adsense_marker_end');
The Explanation
The first line simple declares the function. Then, we echo the Adsense start and end sections, which will insert the comment code telling Adsense what content to look at to determine what ads to show.
The last two lines of each function differ. For the start code, we insert the section before the post box so that it includes the title of the post. For the end code, we insert the section right after the post so it doesn’t include any social media icons, related posts or other irrelevant content you have there.
By letting Google know where your post content is, your ads will become more relevant to each page and should help increase click-through rates and revenues. For non-Thesis users, check out Jim Gaudet’s Advanced Adsense plugin which will do all the nitty gritty for you!
Tags: ads, Adsense, google, money, online, revenue, targeting
Adam,
Thanks for the mention man! I noticed in your code both your functions are named the same, I think you want the top one to be
adsense_marker_start()
I haven’t used Thesis yet, but I am thinking of buying it just to see what the deal is..
Good catch Jim, fixed it in the post. Thanks for the keen eye, somehow I mucked that up when copying and pasting from my blog where I inserted that code…
As for the mention, thanks for the plugin so this post could become a comprehensive guide to injecting this code for wordpress!
If you do pick up Thesis, would love it if you used the aff link on my personal blog 🙂 The big feature I love about Thesis that made it worth the cost and then some is the custom functions and custom css files, which make upgrading the theme super duper easy. That and the extra hooks, like the ones referenced above, make for some interesting coding opportunities.
No problem, I will use your site when . I am sure I am going to need it, so when I pick up my next client I will probably get the DEV version so I can use for them.
Hey thanks for posting this Adam. Dropped the code into the Tourism Keys Blog, we’ll see if there is any improvement in click thrus (although its certainly a minimal, low priority issue for my content).
cheers,
t.
Hey Adam Thanks for this useful post… I hope this will help