Disabling Adsense Ads on 404 Error Pages in WordPress!

How do I prevent Adsense ads from appearing on error 404 pages and stay compliant with Google policies?

That’s the big question and this article will show you how to use a small piece of PHP code on your WordPress website in order to block/disable Adsense Ads on the undesired 404 pages!

adsense ads 404 pages

Adsense ads not allowed on 404 pages

Google says firmly that “no ads should be placed on any non-content-based pages such as thank you, exit or error pages.

What’s wrong with 404s? Well, a “404 Page Not Found” is actually a HTML error page which is returned whenever someone calls for a page that is unavailable on your website. A 404 page does not have content except a human readable “Not Found” phrase and eventually a search box. Practically it pops up when a visitor clicks on a broken link or makes a typo thus mismatching the real URL of a website’s page.

Since Adsense is a content-based advertising network and error pages usually contain no content, then it is understandable why an error page would not qualify for showing AdSense Ads.

Hereunder you can see the code you need to insert into your website/blog in order to remove Adsense from “Not found pages” and implicitly avert Google’s punishment.

The php-code snippet which hides/blocks Adsense ads on 404’s is:
<?php if (!is_404()) { ?>
ADD HERE YOUR ADSENSE CODE
<?php } ?>
Note: the logic of the code is to let Adsense run on all pages but the 404s!

How to use the above-mentioned php code?
There are two possibilities: you can choose to either 1. insert it in Theme’s .php files or 2. insert it in Theme’s widget area.

1. A straightforward way is to add the snippet into Theme’s files that manage your Adsense adverts. For example, if your ads appear at the header, then insert the code snippet in header.php, if ads appear on sidebar then insert it in sidebar.php, and so on. (Go to Appearance->Editor->edit your .php files)

This approach works as intended but sometimes the adsense ads may not fit perfectly into the design if you use a highly widgetized theme. In that case, follow the second alternative as depicted below:

2. Instead if inserting the code into theme’s .php files as done in option 1, make use of Text (HTML) widget (Appearance->Widgets) to add Adsense ads code (wrapped in php scripts) to your website. You have to be aware at this point that the code above does not take effect yet because the “Text” widget is unable to understand the php scripts, however do not worry because there is room for a workaround: convert the text-based widget into php-executable widget by inserting the following code lines into the functions.php file of your template.

add_filter(‘widget_text’,’execute_php’,100);
function execute_php($html){
if(strpos($html,”<“.”?php”)!==false){
ob_start();
eval(“?”.”>”.$html);
$html=ob_get_contents();
ob_end_clean();
}
return $html;
}

Save

Kesar offers effective cure for low libido and premature ejaculation are some cheap viagra tablet of them. Every couple has viagra sample online http://pdxcommercial.com/wp-content/uploads/2017/02/Multfam-Package-6th-St..pdf their own characteristics in the sexual life. A man’s life is closely related to the woman factor and about 30% pure male factor. viagra on line Ajanta https://pdxcommercial.com/wp-content/uploads/1970/01/FOR-LEASE-flyer-working-document-NRV-151209.pdf purchase levitra online pharmacy brought this medicine in the light and endeavored to solve issues concerned with the ED and its treatment. Save

Save

Save

Save

Save

Save

Save

Save

Save

Save

Save

Save

Save

Save

Save

and you are done! The Adsense ads should be nicely displayed (via widgets) on all your blog’s pages except the error 404’s.

Save

Save

Save

Save

Save

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.