Tagged: ,

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1256868

    I am trying to get this code to load into the page, and having some trouble doing it. Can you suggest a way that this can work?

    On my current HTML page, the script is in the Head, and then in the Body.

    I am updating the rawilson.com website (I’ve needed to get rid of the Flash for a long time!!). I am going to buy a new Enfold theme to use, but I have tried to set up this code on another Enfold website I have, without luck. Take a look at it now in action. It is the text that begins, “About Bob.” Every time you reload the page, you get a different random essay.

    Here’s the active page: http://www.rawilson.com/about.html
    I’ve pasted in the Head and Body scripts into the Private Content section.

    Thank you for any help you can give.

    #1257304

    Hi rasa,

    You can put that js code in the wp_footer hook (can be added in the head but it’s not a good practice).
    Just put the script inside this code:

    //-------------------------------
    // Custom script in footer 
    //-------------------------------
    
    function custom_script_name(){
    ?>
    <script>
    
    // Your script here
    
    </script>
    <?php
    }
    add_action('wp_footer', 'custom_script_name');

    For further information, please check: https://kriesi.at/documentation/enfold/add-custom-js-or-php-script/#add-a-script-to-footer-section

    Best regards,
    Nikko

    #1257317

    Thanks, Nikko, but the script is in two parts: one part is now in the head, but the other part needs to be in the Body. Scroll down to the bottom of the code, and you’ll see the part that goes in the Body. I tried using the Code Block, but that didn’t work.

    #1257514

    Hi,

    You can use the wp_body_open hook to place your script in the body of the page:

    function script_in_body(){
    ?>
    <script>
    
    // Your script here
    
    </script>
    <?php
    }
    add_action('wp_body_open', 'script_in_body');

    Best regards,
    Rikard

    #1257737

    Hi Rikard, that didn’t seem to work. I’ve added the Header script via a “Header and Footer Scripts” plugin. I tried adding the Body script in a Code Block and a Text Block and neither one worked. Any ideas? Am I doing something wrong?

    Thanks as always for your help!!

    #1257777

    Hi rasa,

    Please copy the code to the text editor and replace all the double ad single quotes, they are not the kind that is used in programming.

    Also, you have the script tag twice.

    Best regards,
    Victoria

    • This reply was modified 4 years ago by Victoria.
    #1257788

    Replace with what? And did you mean “and” or “ad?” – “replace all the double ad single quotes”

    I think I put in the wrong code above. I’ll attach both the Header code and Body code in this message. The code I’ve been using didn’t have that double script tag.

    This code is currently working without a problem on this page: http://www.rawilson.com/about.html
    It starts building the random text just after the H3 “About Bob’s Works.”

    #1257890

    Hi rasa,

    I have posted in private content the codes used for the two scripts.
    I’m not really sure though if the code works or know the errors it has.
    Hope it helps.

    Best regards,
    Nikko

    #1257906

    Thanks Nikko! That seems to work perfectly.

    #1257913

    Hi rasa,

    We’re glad that we could help :)
    Thanks for using Enfold and have a great day!

    Best regards,
    Nikko

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘Adding javascript to Head and Body’ is closed to new replies.