Block code from firing on 404 page only?

  • shtfpreps

    #49560

    I am testing Google AdSense Auto Ads, the ad code is inserted in the header.php file so it appears on all pages. I do not want the ads to show on the 404 page, so the following code was suggested and inserted in the header:

    <?php if (!is_404()) { ?>
    AdSense Auto Ad code is here
    <?php } ?>

    This does not seem to be working, is there a better solution to blocking ads in the header file only on 404 error pages?

    Thank you in advance.

    Admin

    Syahir Hakim

    #49566

    Graphene automatically redirects 404 hits to search results for the words in the URL. Therefore, you’ll need to check that it’s not a search results page triggered from 404 page as well.

    Try this:

    <?php if (!is_404() && ! isset( $_GET['search_404'] ) ) { ?>
    AdSense Auto Ad code is here
    <?php } ?>
    

    shtfpreps

    #49570

    That did it! Thanks Syahir.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.