Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #788994

    Hi,

    I like to add the new google adsense code only in the blog header, because right know, I past it into the normal header.php and get on every page the google ads. Is there an option to edit the blog header? Where can I find it or what do I have to do?

    Thats what I want only for my blog pages:
    https://support.google.com/adsense/answer/3213689?hl=en

    I dont want to have the ads on my lega sites, or on my frontpage.

    Thanks,
    Chris

    #788998

    Hi, litte update:
    I copied the header.php with the working adsense code and called it header-adsense.php.
    Then, I deleted the adsense code in the normal header.php.
    In the single.php I changed “get_header();” in “get_header(‘adsense’);

    But there is still no results for that, because now, I dont see any ad on my page.

    #789021

    Update: Seems that it doesnt matter what I change in the single.php – nothing becomes visible at the end?! Why? Why cant I use a modified single.php in my child theme? Any other ways to get it done?

    #789054

    Hi,

    You could use a conditional to set what pages you show ads:

    if (!is_page(10, 55)) {
     Your adsense code here
    }

    Replace the numbers in the function with the IDs of the pages you don’t want to show adds on. https://developer.wordpress.org/reference/functions/is_page/

    Best regards,
    Rikard

    #789084

    Hi Rikard,

    thanks for your help. I tried it now with this code:

    <?php if ( is_single() ) { ?>
    [Adsense-Code]
    <?php } ?>

    in the header.php and it works great.
    But I am still wondering, why the changes of my single.php had no impact of the real (non child theme file) single.php.

    Anyway, it works now, you can close the thread.
    Thanks

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.