Site logo

Archived topic

Adding Javascript code

22 replies · Started by Marga on January 18, 2019

Viewing posts 1–15 of 23

Hi, how could I add a javascript text tag (Linkedin Insight tag) just above of </body> tag? I'm using the child theme.

Thank you very much

Hello, I am also using a Hook Element to add Javascript.

To run the <script> with minimal effect on pagespeed, where should it be placed?

Hi there,

If possible you would ideally want to add the <script> to the Footer via the wp_footer hook.
This means that script won't be fired until after the browser has parsed the HTML in the body. So its less likely to tie up the browser that in turn may slow down the rendering of the page.

But ... it all depends on what the script is doing.

What is the script for?

Sounds to me the kind of script that can fire from the wp_footer

Sounds good, thank you,

Would there be any benefit to adding async or defer to this <script>? Or, since it's already in the footer, would those not have an impact on pagespeed?

If its in the footer then you should not need to add either of those attributes.

Ok I will not add those attributes. Thanks for your help!

You're welcome

Hello, I'm trying to add a script to my site, following these directions: Include this Lightframe API script tag in the body of your page, preferably just before the closing </body> tag: <script type="text/javascript" src="https://fareharbor.com/embeds/api/v1/?autolightframe=yes"></script>

I created a hook but wasn't sure where would be "just before the closing body tag. I tried generate after footer, but that's not working. Any ideas?

Hi Jason,

You can use the wp_footerhook, and set the element's priority to 100.

Thank you, Ying. That didn't work. Adding that script just before the closing tag is supposed to open booking forms on my site. For example, https://charlestonscactivities.com, click any Book Now button and it will open the form while the URL stays the same. On my site, https://milehighactivities.com, that doesn't happen. The form opens under a different URL.

Thank you. I shall do that :)

This archived topic is closed to new replies.