How to Disable / Remove / Block Adsense Ads on 404 Not Found Error Pages in WordPress!!!

How to disable Adsense ads on Not Found error pages in WordPress?

This post aims at providing you with the PHP code snippet you need to use on your WordPress-powered website in order to prevent Adsense Ads from appearing on 404 error pages!

404 not found pages not eligible for Adsense Ads

404 not found pages not eligible for Adsense Ads

Google policies! It is well known that Google does not want Adsense ads to pop-up on 404’s. According to its ad placement policies, “publishers are not permitted to place ads on any non-content based pages like thank you, log in, exit or error pages.” Generally speaking, you shall not authorize or encourage the display of any Ad(s), Link(s), or Referral Button(s) on any error page. In conclusion: No Google ad may be placed on any non-content-based pages like the 404s”.

What are 404s? A 404 or Not Found error message is a HTTP standard response code to point out that the client was able to make communication with the server, but the server could not deliver what was requested. Practically it pops up when a visitor clicks on a broken link or makes a typo thus mismatching the real URL of your website page. A 404 Error Page does not have much content as the server returns a HTML page that has just the 404 response code followed by a human readable “Not Found” phrase.

Since Adsense is a contextual-based advertising network and error pages usually contain no content, then it is obvious that a regular error page almost certainly would not qualify for AdSense ads display.

Fixing the problem: Disabling Adsense on 404s!
In the following you’ll find the code you have to embed into your website/blog in order to disable Adsense on “Not found pages” and implicitly avoid getting punished by Google.

The small chunk of php code which does the great job is:

<?php if (!is_404()) { ?>
ADD HERE YOUR ADSENSE CODE
<?php } ?>

There are two options to play with the above code:
Get medical help for existing sexual problem- If your problem does not cheapest generic tadalafil get under control and continue to hit your emotion, get medical help as soon as possible. For others, it becomes more viagra österreich convenient to take since you can take the course from anywhere that has internet access. Besides a healthy, it is cheap sildenafil 100mg equally important avoiding unhealthy eating which may involve eating fast food, junk food, spicy food or oily food. In all these instances, the intake has to be just purchase levitra Prices applied and get result within five minutes. 1. Via Theme’s .php files
2. Via Theme’s widgets area.

1. In the first case you just have to insert the snippet into the php files (Appearance->Editor->php files) that handle the Adsense ads (e.g. header.php, sidebar.php or single (post).php). It works nicely but it might not fit perfectly in terms of design if you use a heavily widgetized theme. If that’s the case, then you may use the second possibility:

2. Many people who monetize their blogs just simply use the “Text” (HTML) widget (Appearance->Widgets) in order to add the Adsense codes to their site. However, the above php-code alone does not take effect because a Text Widget does not really understand the php scripts, but a workaround is available: converting the text-based widget into php-executable widget and that can be simply done by inserting the following lines of code into the function.php file of your template (search for functions.php in Appearance->Editor).

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;
}

…and that’s it! Now the Text widget would be able to execute the php-snippet that wraps your adsense code and what you have to do is just to add the widget to the section of your website where you want adsense ads to appear (header, sidebar, footer, etc). As a result of the trick, no ads should be displayed on 404 error pages.

Save

1 Response

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.