Community Forums › Forums › Archived Forums › General Discussion › Adding script before the head tag for Adsense asnychronous code
Tagged: script to head tag
- This topic has 10 replies, 3 voices, and was last updated 9 years, 10 months ago by afinevo.
-
AuthorPosts
-
May 30, 2014 at 10:22 pm #107576afinevoMember
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 #107601Brad DaltonParticipantThe 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
May 31, 2014 at 2:37 pm #107657afinevoMemberThanks 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 #107661Brad DaltonParticipantThis is the correct function to use for scripts in WordPress , but not for displaying ads http://codex.wordpress.org/Function_Reference/wp_enqueue_script
May 31, 2014 at 3:42 pm #107664SummerMember@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 DarkMay 31, 2014 at 3:43 pm #107665afinevoMemberHey 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 #107671SummerMemberYou'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 DarkMay 31, 2014 at 4:10 pm #107674afinevoMemberHey 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 #107676SummerMemberAnd 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 DarkMay 31, 2014 at 5:03 pm #107678SummerMemberI 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 DarkMay 31, 2014 at 8:19 pm #107692afinevoMemberThanks 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
-
AuthorPosts
- The topic ‘Adding script before the head tag for Adsense asnychronous code’ is closed to new replies.