remove adsense from pages

  • tommyboy

    #6880

    I have 3 ad-sense locations, one using an action hook, one using a side-bar widget and one using the theme’s option (and child theme).

    Through a plug-in I can disable the action hook and the side-bar widget ad locations on pages.

    Is there a way to disable the theme’s option ad-sense on pages?

    Thanks

    Prasanna SP

    #35919

    Moved to Support. Please post in the correct section next time.

    tommyboy

    #35920

    Can you tell me how? I know I can disable them on the front page, but I want to disable them on my static pages only.

    Prasanna SP

    #35921

    Add this to child theme functions.php

    <?php
    function hide_adsense_if_page() {
    global $graphene_settings;
    if(is_page() ) {
    $graphene_settings['show_adsense'] = false;
    }
    }
    add_action( 'template_redirect', 'hide_adsense_if_page' );

    Untested and sent from mobile. Check syntax for errors before using the code.

    tommyboy

    #35922

    Awesome! that totally works. What if I need it disabled on Archive pages and tag archives?

    Thanks

    Prasanna SP

    #35923

    Replace

    if(is_page())

    with

    if(is_page() || is_archive () )
Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.