With the Genesis theme framework, adding “blocks of code” and placing them into certain areas on a site can easily be done with action hooks. The following tutorial will walk you through how to add Google AdSense to your posts.
Below you will see a screenshot that will show you the result of this tutorial:

Step #1
The first thing you’ll want to do is establish the CSS that you’ll need for the AdSense block. Inside your child theme’s style.css file, add this code:
/***** AdSense Post ********************/
.adsense-post {
float: right;
margin: 0 0 10px 10px;
}
This piece of code will create a container that will float to the right and be wrapped by the post content. If you want the AdSense block to be floated left, simply change the code to this:
/***** AdSense Post ********************/
.adsense-post {
float: left;
margin: 0 10px 10px 0;
}
Step #2
Next, you’ll want to create a file where you will place your AdSense code. You will also need to define the container for the code as well, so you create a file called adsense-post.php and place this into it:
<div class="adsense-post">
<script type="text/javascript"><!--
google_ad_client = "pub-4010093622692910";
/* 250x250, created 7/27/10 */
google_ad_slot = "3220529950";
google_ad_width = 250;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
Obviously you will replace the sample AdSense code with your own.
Step #3
Now that you have defined the style and created the php file for your AdSense code, you have to establish a way to implement it into your site. Open your child theme’s functions.php file and find this code:
<?php
// Start the engine
require_once(TEMPLATEPATH.'/lib/init.php');
Immediately after that, place the code below:
// Place Google AdSense code into post
add_action('genesis_before_post_content', 'include_adsense_post', 9);
function include_adsense_post() {
if ( is_single() )
require(CHILD_DIR.'/adsense-post.php');
}
The code above creates a function that says “if this is a single post, hook the adsense-post.php file just above the post content”. Because you defined your Google AdSense container to float: right, this allows the post to wrap itself around your box.




This process seems simple enough. Thanks for the how-to. It is much appreciated!
Excellent.
I like how it’s simple, and broken down into step-by-step.
Thanks Brian,
Jim
Thank you for the how-to, Brian. I’m starting to build some sites for myself to make some money off of adsense. So this info couldn’t have come at a better time!
Adam
Hey Adam – glad to hear it… and glad that the Quick Tips we’re putting out will be of use to folks!
Thanks Brian..how do I replace the adsense plugin (acmetech.com/blog/adsense-deluxe/) with this and retain all current ads? I’ve been using the plugin on my blog for years but would like to improve placement of ads..perhaps it would improve revenue.
How are you implementing the AdSense Plugin now into your site?
sir, we already have adsense.php.
What will be impact if we use adsense-post.php?
The adsense.php file is what is used to display AdSense after the post, the adsense-post.php file will be the one used to display the post as in this tutorial.
Brian..I add whereever I want the ads to appear (top and bottom of posts)
I guess I could simply leave the plugin activated and use your code for future posts.
Thanks Brian,
I was going to use the hooks plugin for my code. Is your suggestion above better? Should I still alter the css if I use the hooks?
You can user either or – if this is the only thing you’d be using the Simple Hooks plugin for, it might be easier to just insert the code as the tutorial shows. Either way you’d need to add the styling.
This is exactly the kind of code i was trying to work out but end up screwing the theme
Thanks a bunch!
In my functions.php i cant find the “<?php
// Start the engine
require_once(TEMPLATEPATH.'/lib/init.php');" code. It is not there. Using News Child theme.
And yeah – ive replaced the “TEMPLATEPATH” with my own path.
Are you sure you are using the News child theme? At the top of the functions.php file I see this:
My bad, it was on of the sites where i didnt use the Genesis Framework – just the News child theme. Is it possible to something similar without the Genesis Framework?
Oh my God! Finally I’ve found how to do this without using any stupid plugin. You have no idea how much you have helped me. I’ve tried a dozen of plugins that added their ads too and so on, stealing my clicks, etc. This is perfect!
Thank you x 1000
Hi ,
i cant see step 2 and 3. The code seems to be missing?
Thanks, fixed now.