How to Add Custom Banner Ad in Thesis Theme Header

January 23, 2010 in Thesis Theme | View Comments

I’ve been asked how did I put Adsense in the header of my Thesis Theme. I’ll tell you how, it’s pretty simple. You’ll have to insert a bit of code in custom_functions.php and custom.css files.

First, put this code in your custom_functions.php:

function header_ad() { ?>
<div id="header_ad">
PUT HERE YOUR ADSENSE CODE
</div>
<?php }
add_action('thesis_hook_header', 'header_ad');

Replace the “PUT HERE YOUR ADSENSE CODE” with your Google Adsense or some other banner ad code.

Second, insert the following code in your custom.css file:

.custom #header_ad {
float:right;
position:absolute;
width:468px;
height:60px;
top:35px;
margin-left: 45.5em;
}

You’ll have to change margins to fit your blog design, but basically, this is it.

If you enjoyed this article, you might also like:
  1. Clickable Header Image in Thesis Theme
  2. Thesis Theme Tutorial: How to Add a Second Navigation Menu
  3. How to: Add Tweetmeme Button to Byline
  4. Thesis Theme Tutorial: Move Comments Link from Below the Post to Byline
  • Thanks a lot ! It just worked like charm. I spent 5 hours trying to customize the thesis header. I was totally doing something wrong to fix a div. Your code just saved my time !
  • Thanks for the tutorial Marko, I faced problem when I tried to paste 2 banners coding in my thesis theme, and now I use your coding for 1 banner and another banner remained the existing coding. Now both of them work well.

    Thanks again Marko!

    Regards,
    Lee
  • I'm glad you found my post helpful for you :)
  • Hi, thank you for the code. It works great on my site except for one thing. The position of my ad in Firefox and Opera is different than in IE. Do you know what to do so that the ad appears in the same location in the header across all browsers?
  • I think it's because you're using the code with the iframe and you set something wrong. By the way Google does not allow displaying adsense inside iframes. If you copy the exact code I posted here, it should work. Regards.
  • Btw, here's what Google has to say about their ads and iframes:
    "Our targeting technology is not optimized to serve ads within a separate IFRAME. If you placed the AdSense code in a separate IFRAME, your site may display less targeted ads or public service ads. For better results, please implement our ad code directly into the source of your webpage. Once you make these changes, relevant ads may not appear immediately. Until we are able to re-crawl your site, which may take up to 48 hours or more, your page may continue to display untargeted or public service ads." This means that you can put ads in iframes, it's just not recommended. (Info from https://www.google.com/adsense/support/bin/answ...)
  • When I inspected your website I noticed the code was inside an iframe. I thought Google didn't allow to put adsense in iframes, but appears it's just not recommended. Thanks for the info.
    To be honest, I don't know why it doesn't work on your site, sorry.
  • I copied and pasted your code exactly. Not sure what your comment about iframes means...I know very little about programming, but was just after the same effect that you have in your header, and noticed that you have Google ads there too (I saw it on http://hegeeks.com/?p=978&preview=true). Btw, Opera, Chrome, and Firefox all display correctly. Only IE doesn't. Thanks anyway.
  • Hey a bit off topic but have you got a tutorial on how to put a custom banner (not an ad) in thesis, or is it roughly the same?
  • I'm not sure I fully understand what you mean. Would you like to replace header logo and tagline with your custom banner? Or would you like to put a custom banner in the same spot as I have Adsense?
  • on my site I have text saying TheInfoPreneur etc, I would like to replace that with my logo, do you know how to do that?
  • Just letting you know that I figured out how to replace the text logo with image logo in header.
    In fact, now I did it on my Twitter Tips blog.
    Here's the tutorial:
    http://hegeeks.com/blogging/thesis-theme/clicka...
  • Thanks brother, off to check it out now
  • Don't know it out of my head. It's not the same as this function. You'd have to make a function which removes the text and replaces it with an image.
    I'll try to find this out!
blog comments powered by Disqus

Previous post:

Next post: