Archived topic
Adding google page level ads
13 replies · Started by CRISTO on December 8, 2017
I want to install Google page level ads on my site. These are different from the usual Google Adsense ads that I already use.
Here are the instructions they give:
Place this ad code in the <head> tag (or at the top of the <body>) of the pages where you want to show the ads. It’s the same ad code for every page and site, and you won’t need to change it even if you adjust your Page-level ads settings.
Do I need a plug in to do this or is there an easier way? Can I just use custom CSS?
Hi there,
According to the instruction, wp_head and before header hook should both work: https://docs.generatepress.com/article/hooks-overview/
Thanks, Leo...I assume I add it in GP Hooks where it says "wp_head", is that correct?
Yes
One more thing....do I click "execute PHP" or not?
Depends the code is PHP or not :)
This is the code...not php is it? I don't really know what php looks like, believe it or not.
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "ca-pub-1347297678313627",
enable_page_level_ads: true
});
</script>
Leo here is what I have now in GP Hooks (one for Google analytics and the new google adsense I just added:
define( 'GENERATE_HOOKS_DISALLOW_PHP', true );
<!-- Clickx Analytics --> <script type="text/javascript">!function(e,n,o,t){var r=n.createElement(o);r.src=t+"?time="+(new Date).getTime(),r.async=!0,r.onload=function(){ClickxTracker.init({twId:"EaD3myHiTSw", apiUrl:"https://app.clickx.io"})},r.onerror=function(){console.log("Error")},n.getElementsByTagName("head")[0].appendChild(r)}(window,document,"script","https://app.clickx.io/clickx-tracker.js");</script><noscript><p>
</p></noscript><!-- End Clickx Analytics -->
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "ca-pub-1347297678313627",
enable_page_level_ads: true
});
</script>
That's not PHP so you don't need to check the box :)
Thanks.
Well, Leo I did something wrong. Marked this as resolved, but then when I look at my site in real time it has the message
define( 'GENERATE_HOOKS_DISALLOW_PHP', true ); shown at the top of each page, so don't know what I did wrong. Here is what I have in GP Hooks:
define( 'GENERATE_HOOKS_DISALLOW_PHP', true );
<!-- Clickx Analytics --> <script type="text/javascript">!function(e,n,o,t){var r=n.createElement(o);r.src=t+"?time="+(new Date).getTime(),r.async=!0,r.onload=function(){ClickxTracker.init({twId:"EaD3myHiTSw", apiUrl:"https://app.clickx.io"})},r.onerror=function(){console.log("Error")},n.getElementsByTagName("head")[0].appendChild(r)}(window,document,"script","https://app.clickx.io/clickx-tracker.js");</script><noscript><p>
</p></noscript><!-- End Clickx Analytics -->
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "ca-pub-1347297678313627",
enable_page_level_ads: true
});
</script>
Not sure what I did wrong.
This shouldn't be added in hooks: define( ‘GENERATE_HOOKS_DISALLOW_PHP’, true );
See the instruction here: https://docs.generatepress.com/article/disallow-php-execution/
Thanks, Leo. I had it in there before but not sure why.
No problem!