Community Forums › Forums › Archived Forums › Design Tips and Tricks › [Genesis Framework] How do I insert code right after the opening Body tag?
- This topic has 7 replies, 2 voices, and was last updated 8 years, 10 months ago by Erik D. Slater.
-
AuthorPosts
-
June 6, 2015 at 1:38 am #155067mywifemakesMember
Hey there!
I use Genesis Framework for WordPress. I'm VERY noob so please forgive me if my question is an easy one for many others.
One of my ad networks is requesting me to place some JavaScript right at the start of the <body> tag. As they instructed:"For maximum speed, steps 1 and 2 must be called at the very beginning of the <body> tag. During our testing, we have found that lower placement of this code can cause issues with ad selection not responding before the display call is made"
I am aware that the general settings of Genesis allows me to put code right before the closing </body> tag. But how can I go about doing this near the opening tag? Could somebody please show me with an example JavaScript placed in, please? I'm unaware of how to even close the coding command.
I tried looking into the header and footer.php but was unable to find where I should place the JavaScript code. 🙁
Thanks so much for any assistance offered! Appreciate it!
June 6, 2015 at 2:11 am #155071Erik D. SlaterMemberTake a look at this StackOverflow thread.
You were in the right general area, i.e. header.php 🙂
If you are using a child theme, copy the header.php file from the Genesis framework parent theme into your child theme folder, and make your changes there, i.e. don't edit the parent theme files.
Erik D. Slater: Digital Platform Consultant • LinkedInJune 6, 2015 at 2:29 am #155074mywifemakesMemberThanks so much for the reply! Appreciate it.
I'm still a little confused as to what to do. I'm using Foodie Pro along with Genesis, for reference. 🙂
Here is the code I need to enter. I've changed the ID number for privacy reasons.
1. Load static js file
<script type="text/javascript" src="http://www35.sitename.com/gad/sitenameadapt_jsapi.act?afid=17345057XX"></script>2. Declare ad slots and load all ads at once.
<script type="text/javascript">
var window_w = document.width || document.body.clientWidth;
/*check how wide a browser is */
if (window_w >= 728) {
SiteCreateSlot("17345057XX", "728x90", "Leaderboard");
}
SiteCreateSlot("17345057XX", "300x250", "Rectangle");
if (window_w <= 640) {
SiteCreateSlot("17345057XX", "320x50", "Mobile");
}SiteGetAds("17345057XX");
</script>
So how would the code look like and where should I put it to make everything be positioned at the start of the body tag?
I'm so so so sorry if this is such an amateur question! Appreciate your professional assistance!
A step by step instruction would be awesome because I don't know anything about this.June 6, 2015 at 3:00 am #155078Erik D. SlaterMemberMy bad. Actually, all you have to do is add the following to the functions.php file in your Foodie Pro child theme:
add_action('genesis_before', 'genesis_before_ad_slots'); function genesis_before_ad_slots() { ?> PASTE YOUR CODE HERE ... LITERALLY :-) <?php }
so for the code you provided above, it would look like this:
add_action('genesis_before', 'genesis_before_ad_slots'); function genesis_before_ad_slots() { ?> <script type=”text/javascript” src=”http://www35.sitename.com/gad/sitenameadapt_jsapi.act?afid=17345057XX”></script> <script type=”text/javascript”> var window_w = document.width || document.body.clientWidth; /*check how wide a browser is */ if (window_w >= 728) { SiteCreateSlot(“17345057XX”, “728?—90″, “Leaderboard”); } SiteCreateSlot(“17345057XX”, “300?—250″, “Rectangle”); if (window_w <= 640) { SiteCreateSlot(“17345057XX”, “320?—50″, “Mobile”); } SiteGetAds(“17345057XX”); </script> <?php }
Erik D. Slater: Digital Platform Consultant • LinkedInJune 6, 2015 at 3:02 am #155079mywifemakesMemberAh I see! Thanks so much for the clear description! Can I put this code at any point in the functions file of a Foodie Pro? Any particular position to ensure it is printed early on in the body tag?
You're so helpful, thank you!
June 6, 2015 at 3:08 am #155080Erik D. SlaterMemberYeah ... although placing externally-acquired code snippets at the bottom is probably a good idea ... just to keep it separate from the original code.
Oh ... and by the way ... your question was definitely not "amateur" 🙂
Erik D. Slater: Digital Platform Consultant • LinkedInJune 6, 2015 at 3:25 am #155084mywifemakesMemberYou're the best Erik! Big thanks to you 🙂 you've saved me a lot of headache!
June 6, 2015 at 3:28 am #155085Erik D. SlaterMemberAwww ... thanks for the kind feedback. It was a pleasure helping you 🙂
Erik D. Slater: Digital Platform Consultant • LinkedIn -
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.