Tagged: google adsense
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
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.
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?
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
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