How To Add Banner Rotation To Your Wordpress Blog

If you would like to setup banner rotation on your wordpress blog like you see here at the top and bottom of this page (refresh to see different banners), just use the following code and instructions and you can have rotating banners on your blog in two easy steps.

The banners.php file which will hold the html for the banners and the code you will insert into your theme templates to call the banners.php file. You can actually use text and or banners. Just format the way you want and make sure the entire code is on one line and not wrapped (it may wrap here because of space constraints).

Open a blank text document and start adding your banner code. One per line.

<a href=”URL1″ target=”_blank”><img src=”image1_url” width=”468″ height=”60″ border=”0″></a>
<a href=”URL2″ target=”_blank”><img src=”image2_url” width=”468″ height=”60″ border=”0″></a>

Save this file as banners.php and upload to your server.

Login to your wordpress admin and navigate to the theme editor.

Paste the following code into your index.html file

$quotes = file(“”);
$quote = rand(0, sizeof($quotes)-1);
echo $quotes[$quote];
<br /><br />

Paste it in directly above

<?php if (have_posts()) : ?>

Be sure and change the “” to your domain.

If you want banners to show at the bottom of your page as well, paste the code again directly after…

<?php endwhile; ?>

If you wanted different types of banners showing on the top and bottom, you could create a second banners file and name it banners2.php and then change the code to call that in your second. You could even call one text.php and use only text links instead of banners. Example below.

<div class=”item_class_text”><p><font size=”4″ face=”Verdana”><p>Internet Marketer Gets $87 Million in Google Pay-Per-Click Ads FREE!</font><br><br>And Makes Over $314 Million as a Result! And Now He’s Going to Give You This Same Secret for Next to Nothing! The fact is… ***You DON’T have to pay for another Google AdWords ad ever again!***<br><br><b><a href=””>Claim your copy of Get Google Ads FREE</a></b>!</p></div><hr>

Just create the text link in Frontpage or other html editor and then paste the entire code onto one line in your banners.php, banners2.php or text.php (the file name doesn’t matter as long as you are not overwriting an existing file and you change the code you paste into your template to call the correct file).

Now go paste the code into your other template files where you want the banners to show like your archives.php and single.php

If you want the banners to show on your search results page, edit the search.php and paste the code directly beneath <div id=”content”>

This works on the wordpress theme used on this site and the others I use. Depending on your theme, the place you paste the code may vary. It’s good practice to always copy the code in your template file and keep it in a text document until you are satisfied with the changes so you can quickly restore to previous version if something gets messed up.

In case I didn’t make any sense with this post which would not be completely out of character for me, just leave a comment below if you need me to try and be a little clearer about something.

Also, I didn’t go into it here but if you are familiar with setting up custom category pages (wordpress tutorial), you can create matching banner files and only show relevant advertising on your categories.

There are many affiliate programs which don’t offer banners for their affiliates, some have banners but they are very limited, not the correct size we want or they are over saturated. A quick and easy solution if you are not a graphics pro is to use Banner Generator Pro which is simple to use and will allow you to easily generate custom banners you can use. This is a great way to blend your banners with your websites while displaying a unique banner they’ve not been exposed to on the twenty sites they visited on their way to your site. WATCH THE BANNER GENERATOR PRO DEMO VIDEO

AND… one last thing. You aren’t limited to banners or advertising. You can also rotate random text, such as a quote of the day or other message.

Til next time,

Did You Find This Post Helpful?
Support this author by adding to your favorite bookmark site now. Thanks!

  • Digg
  • StumbleUpon
  • Twitter
  • Mixx
  • Yahoo! Buzz
  • BlinkList
  • Add to favorites
  • Google Bookmarks
  • Yahoo! Bookmarks
  • Facebook
  • Live
  • MySpace
  • Propeller
  • Reddit
  • DZone
  • Faves
  • Simpy
  • Slashdot
  • SphereIt
  • Technorati

6 Responses to “How To Add Banner Rotation To Your Wordpress Blog”

  1. Just wanted to say a real heart felt thank you for your advice. Have been looking for something like this for ages and it has saved me loads of time, I know some people post comments for the sake of it or for building backlinks but i can honestly say that this advice has been extremely useful. Just one question, if I wanted to rotate say 3 text links at the same time is this possible and if so would you happen to have the code to do that? No problem if not but thought i’d ask. Once again a huge thanks from over the pond in the UK!!!

  2. Thank Jonathan, I’m glad it helps.

    You can insert as many as you like. Just name the files banners1.php, banners2.php, banners3.php or whatever you want really and then in the code you paste into your page, just change banners.php to the file you want displayed.



    $quotes = file(””);


    $quotes = file(””);

    Hope that helps!

  3. I think I may have misunderstood your question Jonathan.

    If you meant, can you have the banner rotate through three links without the user actually reloading the page.

    That can be done also.

    Just create a basic page, with a meta refresh and include the banner code on that page and then use an iframe on the page you want the banners to display and rotate.

    There are a few more technical ways to do this. If this is what you need, let me know and I’ll write up a more detailed post.

  4. Great job on your blog.

  5. Great helpful information, Thanks for this nice post, just subscribed your feed, hope you will update new post soon.
    keep it up.


  6. AC, I got your comments but too much html, php to post here so I’m just going to answer your question without posting the comment.

    Make sure you are using the complete path to your images. I took the html you wanted to use in your banners.php file and uploaded it here in a zip file. Just download, unzip and paste into your banners.php file as is. Make sure that each complete banner html is on it’s own line as it is now.

    Add as many lines as you want… one complete banner html code per line!

    If you have any further problems with it just let me know and I’ll be happy to help you in any way I can.

    Take care,

Leave a Reply