Disable Adsense ad code in 404 deleted posts and pages

Question

recently I got deleted some of older posts, now AdSense crawler throws a continuous error so that I used a code to block AdSense on 404 pages,

I found an online solution,

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!

And add below code into functions.php,

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

(this code throws error —- Your PHP code changes were rolled back
due to an error on line 123 of file
wp-content/themes/generatepress/functions.php. Please fix and try
saving again.

syntax error, unexpected ‘)’

0
herbals fresh 3 years 2020-04-01T00:55:26-05:00 0 Answers 76 views 0

Leave an answer

Browse
Browse