WordPress header code for AdSense rule

I’m using WordPress and Google AdSense. Because of Google AdSense TOS which says that it is against the rules to use more than 3 ad units on one page I decide to show another advertise instead of showing four ad units from Google AdSense.

How to show another ads instead of Google AdSense? This simple PHP code will do the trick.

<?php if(is_single()) { 
echo “<div class=’header-ad’>”;
echo (‘<a href=”http://www.yourdomain.com/” target=”_top”><img src=”/NOadd_728x90.jpg”></a>’);
echo “</div>”;?>
<?php } else { ?>

<?php /* Header Ad */
if( get_option(‘freshlife_header_ad_enable’) == ‘on’){
echo “<div class=’header-ad’>”;
echo get_option(‘freshlife_header_ad_code’);
echo “</div>”;
} ?>

<?php } ?>

What this code do? It says, if it is single post inside DIV element show .jpg image which has its own link to some domain. Else, inside DIV element show original ad_code – in this case it is Google AdSense.

Code you see above is inside WordPress header.php and NOadd_728x90.jpg is image in root folder of my site.

This is just a sample of how to use IF – ELSE function inside WordPress to do things you need. Hope this post will help someone. If you have any question use comments and I will try to answer.

Add Comment