Archived topic
Google Ads in header
15 replies · Started by Jamie on January 30, 2019
Hi! I recently added google ads to my website. I have an ad in the header, which used to mean that it was displayed below my site title and menu which were side by side. For some reason, over the last week, the ad has moved to the right of the site title with the menu underneath, which looks bad. Do you know the reason this has changed, and how I can amend it back to how I originally had it?
Thanks!
Hi there,
It looks like the ad is set to be auto-placed.
I think you'd need to choose one of their static ad types, then we could add it where you want using Hooks. Where exactly do you want it to show up?
Hi Tom,
It would be great if I could have the ad below the site title and menu, but before the content starts in the white boxes? I'm thinking of in the grey bit after the site title and menu? or if this is not possible, in a section that is below the site title and menu?
To do that, you can create a new Hook Element: https://docs.generatepress.com/article/hooks-element-overview/
Then add your adsense code into the content area of the hook.
For the actual hook, choose generate_inside_container.
Then set the Display Rules and you should be good to go :)
Thanks, Tom. This worked perfectly. However, what would be the best way to allow the ad to show on pc/desktop, but so it doesn't show on mobile devices?
Thanks
Hi there,
maybe this article will help:
Hi David,
Thanks for the reply, but that appears to be for google ad words. I meant for google adsense where the random ads show up in a banner below my header. I want it to display on desktop but not on mobile.
Thanks
Sorry my bad - i was looking for a way that didn't require hiding it if possible, you could try wrapping it in the is snippet:
<?php
if ( !wp_is_mobile() ) {
/* adsense script here */
}
?>
Thanks David, but that doesn't seem to have worked. Can you see anywehre I've gone wrong with the code below, as where my ad should be it is just showing }?>
<?php
if ( !wp_is_mobile() ) {
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Banner Ad -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6063761039490145"
data-ad-slot="5447386469"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
}
?>
Try this:
<?php
if ( !wp_is_mobile() ) {
?>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Banner Ad -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6063761039490145"
data-ad-slot="5447386469"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<?php
}
?>
I'm afraid that doesn't work either, David. In fact, on mobile, ads are now stuck at the top of both the 'submit' and 'contact' pages, even though I've deleted the ad code and the hooks! Any idea how to get rid of them?!
oh, and I've already tried deleting cache
ignore me David, I've got rid of the ads for now. I'll try this another time I think, unless you know anything else to try. If not, please enjoy your bank holiday long weekend (if you're not working that is!) and thanks for trying.
Jamie
Yeah sorry for the goose chase - we may just have to resort to CSS and hope Google doesn't get mad. If you want to add them back in i can take a look at the CSS you need to hide it?
I don't want to make google mad! Just had a look at a plugin, and 'Advanced Ads' seems to be able to do what I'm after. I'll give it a go over the weekend (unless you think it would be better without a plugin? I don't want the site to slow down...) and get back to you if it doesn't work.