How to: Insert Google Adsense Ads in Genesis Framework?

(Last Updated On: April 1, 2013)

In this article we are going to insert Google Adsense ads in Genesis Framework, wherever in the entire blog template. However, you can also use WordPress plugins to insert Google Adsense ads in your WordPress blog template.

Read: 10+ Excellent Ads Management WordPress Plugins

But the way I’m going to show you is much neat yet a clean way to insert the AdSense ads wherever inside of your blog that uses Genesis Framework. Let’s get in.

Where should be an ad show and where to prevent?

We shall be using conditional tags whether an ad unit should be shown on home or not. For example if we want to add an ad below post title then it’s quite easy but also want this ad prevented from showing in the homepage. This comes many times with many people out there, I myself faced the same problem but now just found a pretty way to exclude the ads from showing up on the homepage maybe from the post, page, archive, category, 404 page etc… All this stuff will be able to covered within a few line of codes. Let’s go… genesis_layout_positions

Insert Adsense Ads in Genesis Framework

All we need to do is to install a simple Genesis plugin which hooks out the codes inside of the whole template from top to bottom.

Oops, let clear this out that it’s not about on Adsense Ads however all the advertisement program can be run with the same  method.

Here what I was talking about Genesis Simple Hooks. After installing this plugin now you’ll have an option in the Genesis Tab called Simple Hooks. Where you can see bunch of input type pointing to following types of hooks:

  1. WordPress
  2. Document
  3. Header
  4. Content
  5. Loop
  6. Post/Page
  7. Comment List
  8. Ping List
  9. Single Comment
  10. Comment Form
  11. Sidebar
  12. And Footer Hooks

Looking the input types for the hooks listed above you’ll be able to understand the entire template about Genesis. How it works with hooks.

What are Hooks?

Initially the hooks were developed by WordPress to let the plugin developers hooks into the rest of the WordPress core functionality. There are two types of hooks (action and filter hooks).

 Actions hooks: The hooks that WordPress core launches during specific points of execution, or when specific events occur. Your plugin can specify that one or more of its PHP functions are executed at these points.

Filters hooks: The hooks that WordPress launches in order to modify the text of various types before adding it to the database or sending it to the browser screen. Your plugin can specify that one or more of its PHP functions is executed to modify specific types of text at these times.

Let me explain a little bit more… For example now if you want to insert AdSense ad below post title. You can easily go through the post/page hooks in simple hooks plugin and find out about the after post title section. The way you will find out the hooks about genesis_after_post_title which will hook the codes below the post title. What if you want this ad not to be displayed in the homepage just in the post/page maybe both. In this condition we use conditional tags in PHP which let us describe further more about displaying ad unit in certain conditions.

Conditional Tags

  1. is_single();          // This will show the ads only in Single Posts
  2. is_page();            // This will show the ads only in Pages
  3. is_singular();    //  This will show the ads on both Pages, and Posts
  4. is_home();        //   This will show the ads on home page/front page only
  5. is_category(); //   This will show the ads when any of category page is being displayed
  6. is_tag();             //   This will show the ads when any of tag page is being displayed
  7. is_404();          //    This will show the ads when 404 not found is displayed
  8. For more Conditional Tags

How to Use Conditional Tags in WordPress?

About how to use the conditional tags to specify whether a widget, header, sidebar footer should be displayed in certain conditions listed above or not… However, we can simply use the following line of codes to show the ads conditionally in Genesis Framework with the help of simple hooks plugin:

<?php if(is_singular()) { ?>
<p>adsense-code-here</p>
 <?php } ?>

The above code will show your AdSense ads in posts and pages as described. So, simply use the plugin simple hooks plugin to display ads clearly. If you want to display ads using multiple conditional tags. Look at the following line of code:

<?php if(is_singular() | is_home() | is_404()) { ?>
<p>adsense-code-here</p>
<?php } ?>

 Genesis Simple Hooks Google Adsense

That’s it… Comments will be appreciated. Let me know if you don’t want to use Genesis Simple Hooks plugin but want to hook the ads in the rest of Genesis child theme without any plugin. I will make you code for wherever you want to display your ads. 🙂 Thanks for reading..

40 comments

  1. I use Ad Injection plugin to show up ad in between the post and for other areas I create a custom widget area as you mentioned above.Recently I wrote an article on same topic.

  2. Hi Muhammad, I used your code for conditional tags with genesis simple hooks to place an adsense leaderboard ad that appears only in the home, category, and 404 pages of my site. Worked like a charm on my first try, thanks!

  3. Hello! Thanks so much for your help on this.

    I’m looking to show the ad inside the post…not on the home page. For example, when you click on the post title link and it takes you to the individual post page, I want to show the ad there, under the title, before the header. I do not want the ad to show on the home page (I already have ads in my siderbar/header for the home page)

    Thanks!!

  4. Hello Muhammad, thank you! so much for this wonderful walk-through.. especially the part about the ‘conditional tags’..that was something that I was missing out till date while trying to put the ad-sense code inside the post body..(It used to get displayed even on all the other sections like homepage 🙂 )..Thank you again and keep writing..

    1. Hey @Renjiv Raman it’s my pleasure and I love sharing informative article, tutorials, reviews on web development niche. Web development is my passion and soon I’ll be writing WordPress plugins too for my fellow bloggers…

  5. Thank you for this article Muhammad. But I have trouble when I try to put the adsense code under the post title and wrap it inside content. The structure getting colapse and the adsense ads overlapping with the article it self. How to solve this? Thanks.

  6. Thanks for info.. I like float ads with 1st paragraph of post like your, Please share how to align adsense and post.

      1. Thanks for reply!! but its now working with my child theme, Even post float with adsense. I think its problem of child theme CSS, I will use this with new child theme.

  7. Hi, thank you for this post but I’m still confuse. I use Genesis Simple Hooks, I have some questions..

    I want to put my GA script exactly below my category menu (please visit my site), where I put my script in genesis simple hooks plugin setting?

    Should I check “Execute Shortcodes on this hook?” and “Execute PHP on this hook”?

    Really waiting for your reply..

    Thank you 🙂

    1. Hi @Kristine,

      You will be able to add your AdSense ads below the category menu by simply adding your Ad code in the genesis_before_content_sidebar_wrap hook. And if you are using conditional tags then you should check both “Execute Shortcodes on this hook?” and “Execute PHP on this hook”? Please don’t check the “Execute PHP on this hook”? if you are not using any PHP tags like that < ?php ?>

  8. Hi Haroon,

    I’m looking at placing some ad on my category/ tag pages using functional hooks. Can you please tell me which hook I should use? I tried using After post/ page content but it displaced my entire content.

    1. Hi @Deepali Jain, you have tried the right hook but you just forgot to use the conditional tags for Category/tag pages…

      is_category(); // This will show the ads when any of category page is being displayed
      is_tag(); // This will show the ads when any of tag page is being

      As I’ve described in my article.

  9. Hi Muhammad

    Thank you for making this post. I am trying to avoid plugins if I can.

    Could you tell me what I would need to add to my functions.php so that I can have an adsense ad right below the Post Title/Author byline in the single blog post.

    Thank you

  10. thanks for this, i have been using ads injection, but since this is still inside genesis themes, i just disabled the ad injection plugin and start using thid, thanks for this.

  11. Thanks bro, this is so much useful for me. Since i use genesis framework, i found many problems including how to insert ads in post body.
    anyway, thanks in advance for your post!!

Leave a Reply

Your email address will not be published. Required fields are marked *