- This topic has 11 replies, 3 voices, and was last updated 7 years, 7 months ago by Tom.
-
AuthorPosts
-
August 24, 2016 at 3:08 am #220886tobymiguel
I am trying to implement Google Ad code into the Page Header content, but each time I try, everything “freezes” and I can’t save or do anything.
August 24, 2016 at 9:54 am #220942TomLead DeveloperLead DeveloperInteresting, can you show me the code you’re adding?
August 25, 2016 at 1:56 am #221131tobymiguelHi Tom
It is just the normal adsense code, example:
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- Ad code --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-00000000000" data-ad-slot="000000000" data-ad-format="auto"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script>
August 25, 2016 at 9:18 am #221222TomLead DeveloperLead DeveloperI just saved that block in the Page Header content area without any issues.
However, adding javascript in there might not be the best idea, and I’ll probably add a filter that prevents that from happening.
One thing you can try is adding your code into a shortcode, and then placing the shortcode in the content area:
add_shortcode( 'adsense', 'my_adsense_shortcode' ); function my_adsense_shortcode() { ob_start(); ?> <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- Ad code --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-00000000000" data-ad-slot="000000000" data-ad-format="auto"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> <?php return ob_get_clean(); }
Then you can use the [adsense] shortcode wherever you like.
Another perk to this is you can change the ad code and it will change it site-wide wherever you’re using the shortcode.
August 30, 2016 at 9:26 am #222516tobymiguelThank you Tom, this is working.
But why are the Page Header Content only displaying on the Home page? Can I make it display side-wide?
August 30, 2016 at 9:59 am #222531TomLead DeveloperLead DeveloperPage Headers are page-specific.
If you want it to be global, you want to use GP Hooks.
August 30, 2016 at 10:28 am #222545Ramesh SrinivasanNice Tip, Tom. Right now I’m using “Ad Inserter” Plugin, but will try your short-code method. Looks slick.
August 30, 2016 at 10:33 am #222549TomLead DeveloperLead DeveloperThanks! π
August 30, 2016 at 10:35 am #222550tobymiguelHey Tom
Can you tell me how to do it with GP Hooks? π
August 30, 2016 at 2:59 pm #222616TomLead DeveloperLead DeveloperYou would just put the shortcode in “Appearance > GP Hooks” in the hook you want (After Header is the same as the Page Header).
August 30, 2016 at 3:44 pm #222625tobymiguelOh I hadn’t activated Hooks… π
Anyway, I tried your suggestion, but then next problem arises.
If you put anything in the After Header hook, it will not display inside a container.
I tried to set the width to 1100px in CSS, but then it is not responsive anymore.
Any suggestion? I’ve tried other hooks, but none of them will display inside the container above the content and sidebar.August 31, 2016 at 12:00 am #222666TomLead DeveloperLead DeveloperHave you tried the “Inside Content Container” hook?
Otherwise, wrap the code in a container:
<div class="grid-container grid-parent"> Your contained content </div>
-
AuthorPosts
- You must be logged in to reply to this topic.