Tagged: head, javascript
-
AuthorPosts
-
October 29, 2020 at 8:31 pm #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.
October 31, 2020 at 7:16 pm #1257304Hi 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,
NikkoOctober 31, 2020 at 7:57 pm #1257317Thanks, 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.
November 2, 2020 at 5:12 am #1257514Hi,
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,
RikardNovember 2, 2020 at 10:45 pm #1257737Hi 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!!
November 2, 2020 at 11:56 pm #1257777Hi 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, 1 month ago by Victoria.
November 3, 2020 at 12:37 am #1257788Replace 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.”November 3, 2020 at 8:18 am #1257890Hi 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,
NikkoNovember 3, 2020 at 9:30 am #1257906Thanks Nikko! That seems to work perfectly.
November 3, 2020 at 10:07 am #1257913Hi rasa,
We’re glad that we could help :)
Thanks for using Enfold and have a great day!Best regards,
Nikko -
AuthorPosts
- The topic ‘Adding javascript to Head and Body’ is closed to new replies.