Rotate Banner Ads In WordPress Without Using Plugins

PHP knowledge can be useful in replicating some of the wordpress plugins with simple php code without the need to add to the list of long plugins one uses on a wordpress blog.Here’s a simple piece of PHP code which lets rotate banners, more specifically for a 125 x 125 ad slots.

$banner_rotate[0]="<a href=''>
<img src='' /></a>";
$banner_rotate[1]="<a href=''>
<img src='' /></a>";
$banner_rotate[2]="<a href=''>
<img src='' /></a>";
$banner_rotate[3]="<a href=''>
<img src='' /></a>";
for ($i=0;$i<=3;$i++){
   echo $banner_rotate[$i];


What this piece of code does is, it stores the ad code in the array with easy banner code stored in a array ie., $banner_rotate [i] where i can be 0 to n ( any number).

Next the shuffle function rotates the contents of all array elements, before looping to select any of the banner.

Next starts the loop which displays all the banners.

Source – WPMods

If your not comfortable with placing php code into your template files, you can try these plugins :

Also Checkout, How To Place Ads In The Middle Of The Post Automatically

Here’s another way to rotate ads., This lets you show a randon ad eveytime a page is refreshed

<?php $rotads = rand(0,1);?>

<?php if ($rotads == 0) {?>

<!—-Place First Banner Code Here –>

<?php if ($rotads == 1) {?>

<!—-Place Second Banner Code Here –>

<?php };?>
This can also be used to do A/B Testing by placing different ads and testing which ad is giving the best results.

The HostGator Ads In the Sidebar on this blog, is implemented using the same above mentioned method.

Similar Post  How To Disable Memory Dump Files and Reclaim HDD Space
Liked It ?? Share It 🙂Share on FacebookShare on StumbleUponTweet about this on TwitterShare on Google+Digg thisBuffer this page

Leave a Reply

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