Disabling/disallowing Adsense in a few places

  • GamingYeti

    #7932

    Hi,

    I just need some help: I want to use google adsense on my blog. But the fact, the the ads show after each post synopis when going to the category view is a pain. Is there an easy way to disable graphene ads only in the archives/categories/tags view of my website?

    Somekind of custom css/html codes?

    Admin

    Syahir Hakim

    #39364

    You would need to use a child theme to achieve this. Are you currently using one?

    GamingYeti

    #39365

    Nope, I don’t even know about such a thing, to be honest ^^”’

    Admin

    Oliver

    #39367

    @ Yeti it is very easy, you can download the child theme from here:

    http://www.prasannasp.net/graphene-child-theme-template/

    Hi Syahir Hakim

    I have a child theme.

    I experience the same thing.

    e.g. http://minmadopskrift.dk/category/dip-dressing, I want to remove the ads here, and on all other categories

    Please inform how to remove ads with a child theme.

    Thanks in advance

    Oliver

    Admin

    Syahir Hakim

    #39368

    Add this to your child theme’s functions.php file:

    /**
    * Disable ads in certain places
    */
    function my_disable_ads(){
    global $graphene_settings;
    if ( is_category() ) {
    $graphene_settings['show_adsense'] = false;
    }
    }
    add_action( 'template_redirect', 'my_disable_ads' );

    Make sure you wrap the code above in PHP’s opening <?php and closing ?> tags.

    Oliver

    #39369

    I am sorry asking again. Here is my child php file. I try to insert the code in several places, but get an error message from w3 total cache, that Minify URL rewriting is not working. I can still see adsense.

    What am I doing wrong? Where would you place the code?

    <?php

    // put your code here
    function graphene_filter_gettext( $translated, $original, $domain ) {
    $strings = array(
    'Powered by %1$s and the %2$s.' => 'Min Madopskrift, min madopskrift på nettet',
    );
    if ( ! empty( $strings[$original] ) ) {
    $translations = &get_translations_for_domain( $domain );
    $translated = $translations->translate( $strings[$original] );
    }
    return $translated;
    }
    add_filter( 'gettext', 'graphene_filter_gettext', 10, 3 );
    ?>

    Prasanna SP

    #39370

    @oliver, try this,

    <?php

    // put your code here
    function graphene_filter_gettext( $translated, $original, $domain ) {
    $strings = array(
    'Powered by %1$s and the %2$s.' => 'Min Madopskrift, min madopskrift på nettet',
    );
    if ( ! empty( $strings[$original] ) ) {
    $translations = &get_translations_for_domain( $domain );
    $translated = $translations->translate( $strings[$original] );
    }
    return $translated;
    }
    add_filter( 'gettext', 'graphene_filter_gettext', 10, 3 );

    /**
    * Disable ads in certain places
    */
    function my_disable_ads(){
    global $graphene_settings;
    if ( is_category() ) {
    $graphene_settings['show_adsense'] = false;
    }
    }
    add_action( 'template_redirect', 'my_disable_ads' );

    It is better if you create a separate thread for your issue. It becomes difficult to respond to OP’s question if somebody hijacks the thread.

    Put code in between backtick (

    Code:
    `

    ) characters here in the forum. It’s usually located above the Tab key on your keyboard.

    Oliver

    #39371

    Thanks for your help.

    I’m sorry. It was not my intention to take over this thread.

    This code does not work for me, with or without the closing tag, or any other way.

    I will try to insert the code differently

    Oliver

    #39372

    I think I know why it did not work out for me.

    It is because I have inserted adsense in an action hook and not in the graphene options.

Viewing 10 posts - 1 through 10 (of 12 total)

You must be logged in to reply to this topic.