• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Adding script before the head tag for Adsense asnychronous code

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Adding script before the head tag for Adsense asnychronous code

This topic is: resolved

Tagged: script to head tag

  • This topic has 10 replies, 3 voices, and was last updated 11 years, 8 months ago by afinevo.
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • May 30, 2014 at 10:22 pm #107576
    afinevo
    Member

    Hey everyone. I'm in the process of trying to convert my Adsense ads from synchronous to asynchronous in the body of my content. It seems to be a fairly simple process. From what I have read, it just requires adding script before the head tag and then substituting the synchronous code with the asynchronous. I have the eleven40 theme and I added the script to the header script box in Theme Settings. So far I have not been successful adding the script this way - the ads do not load.

    Am I adding the script in the wrong spot? Is there a better way to add the script above the head tag? Any help is appreciated.

    Thanks!

    http://allgaragefloors.com/
    May 31, 2014 at 3:53 am #107601
    Brad Dalton
    Participant

    The Genesis > Theme Settings > Header & Footer Scripts boxes are for tracking scripts Like GA which output in the source code and not on the front end.

    I suggest you either:

    1. Hook in the scripts directly from your functions file.
    2. Create new widgets in the positions you want to display the ads. Best option


    Tutorials for StudioPress Themes.

    May 31, 2014 at 2:37 pm #107657
    afinevo
    Member

    Thanks Brad, but I don't want to create a widget in this case. I've searched for hours now looking for a way to hook the script into the functions file, but I'm not finding what I need or in many cases do not understand.

    Every post I've read about converting to asynchronous Adsense code makes it seem so damn easy, but they all assume that everyone knows how to add the script to the functions file. Argh!!!

    This is what I'm trying to add:

    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

    It's supposed to be added above the head tag which I've read is in the header.php file for WordPress.

    Can you or someone else possibly explain how this is done?

    Thanks again.

    May 31, 2014 at 2:53 pm #107661
    Brad Dalton
    Participant

    This is the correct function to use for scripts in WordPress , but not for displaying ads http://codex.wordpress.org/Function_Reference/wp_enqueue_script


    Tutorials for StudioPress Themes.

    May 31, 2014 at 3:42 pm #107664
    Summer
    Member

    @afinevo, I think you're confusing Adsense with Google Analytics.

    The Google Analytics code goes in the header, for tracking purposes. The Adsense ad code only goes where you want to place your ads, never in the header.

    The instructions for the Adsense asynchronous codes do not say to put any bit of that Adsense code in the header:

    https://support.google.com/adsense/answer/3221666?hl=en

    Go to the section where it gives an example of the full Adsense code... the snippet you're using is missing the entire section that contains the ad code.

    It also says to put the code where you would normally put your ad, which these days, 95% of the time is in a sidebar widget, or a widget before or after your post content.


    WordPress / Genesis Site Design & Troubleshooting: A Touch of Summer | @SummerWebDesign
    Slice of SciFi | Writers, After Dark

    May 31, 2014 at 3:43 pm #107665
    afinevo
    Member

    Hey Brad. I had found that previously and it's not quite helping me out. I believe it's a bit over my head for what I'm trying to do. I might not be explaining myself correctly.

    I'm not trying to run Adsense ads through functions.php. According to this post here, http://www.liberiangeek.net/2013/07/the-best-way-to-add-google-adsense-asynchronous-script-on-your-blog/ this is how to place an asynchronous Adsense ad. All I'm trying to do is use the asynchronous code in place of the synchronous for my current ad placements. It's the placement of the java script in the head tag that is driving me crazy.

    May 31, 2014 at 3:50 pm #107671
    Summer
    Member

    You're trying to replace the wrong thing 🙂

    For example, on your website: http://allgaragefloors.com/best-cheap-garage-tiles/

    The Adsense codes you would replace are the ones in your left sidebar, in the middle of the post content, and in between the share buttons and the comments at the bottom of the post.

    That's where you should be replacing Adsense synchronous codes with asynchronous codes. The header script is for Google Analytics tracking only.


    WordPress / Genesis Site Design & Troubleshooting: A Touch of Summer | @SummerWebDesign
    Slice of SciFi | Writers, After Dark

    May 31, 2014 at 4:10 pm #107674
    afinevo
    Member

    Hey Summer, thanks for the quick reply. The asynchronous Adsense codes do not work within the content of a page on my site for some reason. The one in the sidebar widget does. I read somewhere that asynchronous code does not work in the content of a responsive site unless you add the first snippet of java script to the head of the page. This is the first snippet in the asynch ad.

    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

    I've been at this for a solid day and a half trying to make these work within the content of a page and I'm running in circles now. I may be solidly confused. All I know is that just replacing the async code for the synch code does not work.

    Thanks again!

    May 31, 2014 at 4:54 pm #107676
    Summer
    Member

    And you converted all the ads you're trying to replace to use the asynchronous codes? You have to edit your ads at Google and switch all the ones you're trying to use. I don't think they'll work if they haven't been switched but you're trying to use the async scripts.

    Nothing I've read at Google suggests that the ad won't work on a responsive site... the only thing I've read is that you can get away with using that script call once per page, even if you have more than one ad on that page.


    WordPress / Genesis Site Design & Troubleshooting: A Touch of Summer | @SummerWebDesign
    Slice of SciFi | Writers, After Dark

    May 31, 2014 at 5:03 pm #107678
    Summer
    Member

    I just looked at the source for that page link I used above... your mid-page ad is still using the old Adsense code, while the sidebar ad and the bottom ad are using the new code.

    If you switch your midpage ad to use the new async code, then past that code in your mid-page widget, that should fix the issue you're describing.


    WordPress / Genesis Site Design & Troubleshooting: A Touch of Summer | @SummerWebDesign
    Slice of SciFi | Writers, After Dark

    May 31, 2014 at 8:19 pm #107692
    afinevo
    Member

    Thanks for your help Summer. Yes, the bottom is asynchronous because it's in an insert widget. I think you may be on to something about all the midpage ads needing to be changed first to work. I'm going to be doing away with the insert widget and placing some ads manually. I started testing the asynchronous code this way and that's when I started having issues.

    I think I'll close this thread out since it has turned into an Adsense issue and not really an issue with Genesis.

    And thank you Brad for spending time on this.

    Shea

  • Author
    Posts
Viewing 11 posts - 1 through 11 (of 11 total)
  • The topic ‘Adding script before the head tag for Adsense asnychronous code’ is closed to new replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble