[Resolved] Javascript

Home Forums Support [Resolved] Javascript

Home Forums Support Javascript

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1446483
    Janine

    Hiya.

    How can I embed Javascript code in my theme’s header scripts box? And are there any negative consequences to doing so?

    Thank you.

    #1446500
    Elvin
    Staff
    Customer Support

    Hi Janine,

    How can I embed Javascript code in my theme’s header scripts box? ..

    To clarify, did you mean <head> tag or the header section of the theme? These are 2 different things.

    If you meant <head>, you can try this PHP code to add your javascript code.

    function hook_javascript() {
        ?>
            <script>
                'Add your script here'
            </script>
        <?php
    }
    add_action('wp_head', 'hook_javascript');

    For the Header element, you can try using the elements module under GP Premium and simply add your <scrip></script> there.

    ..And are there any negative consequences to doing so?

    More scripts means more things to load. It’ll affect how fast your page loads depending on the script’s complexity.

    For styling scripts, it can affect your page scores/rating on GTMetrix or Google PageSpeed insights if done wrong.(layout flags etc)

    Other scripts may pose security risks. Make sure you completely know what the script does before adding it in to be on the safe side.

    #1447410
    Janine

    Hi, Elvin.

    I am not sure what I mean. Let me double check and get back with you. And thank you!

    #1447703
    Elvin
    Staff
    Customer Support

    Sure, take your time.

    No problem.:)

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