How to Add Google Adsense / HTML Codes to Genesis Without A Plugin

I’ve been using Genesis for quite a while and till just a few hours ago, I didn’t know I could actually do away with the “Post Layout” plugin I’ve been using to add Google ads and other codes to properly format my post pages. Over the last few weeks, I’ve been trying to reduce my number of installed plugins in order to decrease page load time and also CPU usage. From disabling StatPress, Auto Excerpt Everywhere, down to Social Author bio and loads of other plugins, I thought it would be a good idea to use Genesis Hooks and some conditional statements to display ads and other codes instead of relying a third-party plugin I didn’t really need.

Finally, I was able to display the ads and other stuffs just the way I wanted it and right now, I’m using Genesis hooks to display everything you see above and below posts. As a matter of fact, it rather fun digging into the code side of things… got to learn more WordPress conditional statements (I never really did care because I didn’t know how useful they were).

We’re adding these adsense codes or custom PHP / HTML in five positions in this tutorial, it’s up to you to choose where you want your stuffs to appear:

1. The sidebar

2. Below the header

3. Below post title

4. After post content

5. Above posts in archive pages

1. Adding ad codes to the sidebar

Well, I’m not sure I need to explain this but for beginners, you only need to go to Appearance > Widgets. Drag the text widget to your desired location and paste the ad code or custom HTML. That’s it.

2. Adding Google Adsense below the header

I already explained this in a previous post but this is going to be a bit advanced. For someone like me who has a skycrapper on the sidebar and two ad units on post pages, I would like hide that leaderboard below the menu on post pages. This is where conditional statements come in; you only need to add a snippet of code to tell the advert not to appear on single posts and pages.

- Download and install Simple  Genesis Hooks

- Go to Genesis > Simple Hooks

- Scroll down till you get to the content section

- In the box labelled genesis_before_content_sidebar_wrap Hook, paste this code:

<?php if ( ! is_page() && ! is_single() ) {?>
<div align="center" style="width:100%; padding:5px; background: #ffffff;">
YOUR ADSENSE CODE, AFFILIATE LINK OR BANNER HERE
</div>
<?php }?>

- Be sure to mark Execute Shortcodes on this hook and Execute PHP on this hook

The part in red is the conditional statement that tells the ad not to appear on single posts and pages. So, this appears on the home page and all archive pages and with this implemented the right way, you won’t be having more than three ad units on each of your site pages. You can even take this further if you’ve done PHP programming or any sort of programming before. It’ll be much more easier for you to manipulate this statements and make your ads appear exactly where you want them to be.

3. Below post title

Now we’re going to add adsense below post title and we’re still gonna use Simple Hooks and conditional statements. The first time I did this, the Google Adsense ads appeared on archive pages and the home page till I added a statement that forced the ads to appear on single posts and pages only.

- Go to Genesis Simple hooks settings page and find genesis_before_post_content Hook

- In the box, paste this code:

<?php if ( is_page() || is_single() ) {?>
<div align="center" style="width:100%; padding:5px; background: #ffffff;">
YOUR ADSENSE CODE, AFFILIATE LINK OR BANNER HERE
</div>
<?php }?>

- Also, mark Execute Shortcodes on this hook and Execute PHP on this hook

The part in red tells the advert to appear on single posts or pages. It’s gonna be hidden from the homepage and archive pages and I’m sure you don’t wanna show it there, do you?

4. After post content

You’re still using the same code you used right above but you’re only going to add it to a different position, OK?

- Search for genesis_after_post_content Hook

- Paste the code up there in to the box and save.

You’ll probably notice that the post meta (tags and categories) appear above the advert. You can reposition this by marking the box that says Unhook genesis_post_meta() function from this hook?.

- Below the code already in the box, now add this:

<?php
genesis_post_meta()
?>

5. Above posts in archive pages

Still tweaking the conditional statements, we can make ads appear on archive pages only. This include category pages, tag pages, author pages and so on.

To make ads appear directly above posts on archive pages:

- go to Genesis Simple Hooks settings page and search for genesis_before_loop

- Paste this

<?php if ( is_archive() ) {?>
<div align="center" style="width:100%; padding:5px; background: #ffffff;">
YOUR ADSENSE CODE, AFFILIATE LINK OR BANNER HERE
</div>
<?php }?>

There are lots of other positions you can add your codes, you only need to study genesis hooks deeper and learn more about WordPress conditional tags. With this, you can show or hide ads or custom PHP / HTML where ever you want in your Genesis theme.

avatar
Don Caprio is a full time blogger / web designer living in Nigeria and apart from blogging, my other obsession is music. I'm a self-confessed Tupac fan, an iOS lover, an Android user, a Windows 8 power user, a writer with a 5-year old unfinished novel... and the list goes on and on. You can add me on Facebook, follow my updates on Twitter or add me to your circles on ! You can as well grab my feed and get updates through email.
avatar

@doncaprio

Tech blogger at http://doncaprio.com Web designer at http://doncaprio.org
Top 5 Ways to Reduce your Blog’s Bounce Rate http://t.co/sCwot72QHP - 1 day ago
avatar
avatar

Get free daily updates through email

Comments

  1. Hey Your Brain Has Been Over floated.Thanks Alot.Bye bye to mobilepress.Gonna Get it a Try

  2. Simple Genesis Hooks is an awesome way of adding anything to a Genesis theme without using plugins, if you understand the hooks properly as have been explained here, you can easily add anything to your Genesis theme, i have been using it and i can tell its an awesome plugin.
    Nwosu Desmond recently posted..Understanding Search engine ranking factorsMy Profile

  3. Thank You,
    Got my own working already, no need of post layout plugin anymore.
    Derek recently posted..How To Dowload All Your Facebook Pictures And Data With One ClickMy Profile

  4. What a timing! You put up this post at the right time. I in fact wanted to replace my Awesome ads plugin by manually putting up codes using genesis hooks. Any idea on how to put up ad on the 404 error page?

    Also would like to know the HTML code for aligning a bit towards rightside from center in the following code –
    nikhil recently posted..Microsoft Reportedly Developing a Mini Gaming TabletMy Profile

  5. @don you are the boss.. can this work for mobile ads? i’m used to post layout plugin for displaying ad on my mobile version.. After a while i observed that the post layout plugins displays ads on mobile when your operamini is set to desktop view,and doesn’t show when set to mobile view…i Guess the genesis hook can solve my problems. So my ads can show for both

  6. Thanks for this! I have tried using plug-ins but would rather do it this way!

    Anyways, I followed the directions above and some ads are showing up on pages and I only want them on posts (after post content). I added the code to “after_post_content” hook but I don’t want it to display on pages.

    Is there a filter, or way to exclude the ads on pages?

    Here is a link to a page its showing on:

    http://blogaholicdesigns.com/shop/

    I only want the ads on my blog posts.

    Your help would be greatly appreciated!

    Thanks!
    Emily recently posted..Free Fall Blog Templates- Backgrounds-Buttons!!!!My Profile

    • Hi Emily,

      Yes, that’s possible. Just change <?php if ( is_page() && is_single() ) {?> to this: <?php if ( is_single() ) {?>

      That should limit it just to single posts.

  7. You have no idea how much I appreciate it! That worked perfectly! I use a lot of your tutorials and I just wanna let you know I think you rock – you’ve saved me a lot of time!

    Thanks :)
    Emily recently posted..$40.00 Premade Blog Template Collection!My Profile

  8. Plz am using the dynamic view for my Blogger blog. I don’t konw how to paste Ad codes in my blog.
    When i tried pasting one code in my Edit HTML in the eidt template section my account was deleted.
    Plz i need your assistance.

  9. Worked great , Don.

    Many, many thanks.

    I had been looking at a number of options for achieving this(placing ads below header and / or after posts)…and many tutorials I followed caused issues for my site…then I had to go into my Host account file manager to clean it up….
    Though, your simple hooks instruction only needed a few page refreshes and it is working beautifully..

    It works for me when I “don’t ” tick execute short codes and execute PHP, though I am not complaining….

    Thanks again…
    Danny recently posted..Your Vision For Achieving Blogging SuccessMy Profile

  10. Thanks so much! Been searching for the right example to do just what I want to add text at the bottom of pages and posts only and I finally found it here!

  11. nice post in here man
    doncyber recently posted..Considering Which One is Better – WordPress or Blogger?My Profile

  12. @ don…. I will like to paste ads side by side on the same spot as you did yours
    doncyber recently posted..Considering Which One is Better – WordPress or Blogger?My Profile

  13. Bro Mine Always appear on the Homepage why
    Kingsley recently posted..Vitamin A: Vitamin Deficiency DiseasesMy Profile

  14. Hi, can you please tell me, in Gensis theme –
    how to insert adsense ad, below title, right alligned to the post content. I want the ad to be wrapped within the post. I do not want it between the title and the post.

  15. I am looking for the code to put a 728×90 banner under the logo in Genesis framework news theme.. Is there any body can help me..
    Mellisa Miller recently posted..How to understand credit scores betterMy Profile

  16. Great one :) Thanks a ton…
    Karthikh Venkat recently posted..Top 5 Degrees Preferred by Indian studentsMy Profile

  17. Although I have had my adsense account approved over a long while now, I just requested for it to serve on my blog as at 14 hours ago. I was instructed to put the code in my html, so it can be activated.
    I have as well followed the instructions you posted to add my adsense codes, but up till this second I haven’t seen any ads serving on my blog.
    How long does it take to start displaying ads, and is there something I havent done right?
    Thanks for this great piece.
    Selfmadecash recently posted..Event Planning Business And How To Handle Vendors BetterMy Profile

  18. Selfmadecash, that’s correct, your impression first will matter alot, if your impression is okay, live ads will start being displayed on your blog.

    wish you the best.
    Make Money Online writing articles recently posted..How To Make Money Online Writing ArticlesMy Profile

  19. Thank you so much for this helpful post! I’m not very knowledgeable about PHP, but have an ad that I would like to use below the post title on pages and posts, however I don’t want it showing on the archives nor on a few specific posts. I thought I was using the correct conditionals, but the conditionals to have the ad not appear on archives or the specific posts doesn’t seem to be working. Can you offer any advice? Here is the code I was trying:

    <?php if ( is_page() || ! is_archive() || is_single() || ! is_single( array( 17591, 17577, 18390 ) ) ) {?>

    Thank you so much again!
    Michelle recently posted..Easter Word Search #1 – Free PrintableMy Profile

  20. Please can this help in displaying adsense mobile ads too?

  21. great tutorial. i was just looking for the solution of putting the code on multiple places and your tutorial just helped me out. really genesis hooks rocks…

  22. D.c please how can i make the ads appear but on archive and category pages like your and align it left and right??
    Kingsley recently posted..How To Add the Twitter Flying Bird To Blogger?My Profile

  23. Thanks for nice post.
    How to add Google Adsense code without plugins?
    atiqur rahman recently posted..The usefulness of e-mail for students of BangladeshMy Profile

Speak Your Mind

*

CommentLuv badge