[Support request] Adding Javascript code

Home Forums Support [Support request] Adding Javascript code

Home Forums Support Adding Javascript code

  • This topic has 22 replies, 5 voices, and was last updated 9 months ago by Fernando.
Viewing 15 posts - 1 through 15 (of 23 total)
  • Author
    Posts
  • #785305
    Marga

    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

    #785400
    David
    Staff
    Customer Support

    Hi there,

    you can use the Hook Element:

    https://docs.generatepress.com/article/hooks-element-overview/

    Create a new Hook add your script, and select the after_footer hook and then assign the display rules for Entire Site ( or selected pages ) for where you want the script to run.

    #2142411
    Margaret

    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?

    #2142419
    David
    Staff
    Customer Support

    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?

    #2142423
    Margaret

    I am setting up Hubspot Marketing, and they have a <script> to label pages under different asset types (standard-page, landing-page, blog-post, etc.) When a lead comes in, Hubspot will use these scripts to attribute the lead to whichever content type the customer was interacting with.

    https://knowledge.hubspot.com/reports/create-multi-touch-contact-create-attribution-reports

    #2142426
    David
    Staff
    Customer Support

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

    #2142428
    Margaret

    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?

    #2142434
    David
    Staff
    Customer Support

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

    #2142445
    Margaret

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

    #2142453
    David
    Staff
    Customer Support

    You’re welcome

    #2327521
    Jason

    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&gt;

    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?

    #2327545
    Ying
    Staff
    Customer Support

    Hi Jason,

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

    #2327565
    Jason

    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.

    #2327579
    Ying
    Staff
    Customer Support

    The script is added right before the </body> tag:
    https://www.screencast.com/t/R3qAV9C3yO

    If the script doesn’t work as you expected, it’s better to reach out to the script’s provider ๐Ÿ™‚

    #2327595
    Jason

    Thank you. I shall do that ๐Ÿ™‚

Viewing 15 posts - 1 through 15 (of 23 total)
  • You must be logged in to reply to this topic.