Archived topic
Where do i find the document ready block file to ad js?
14 replies · Started by Carsten on December 17, 2018
Hi there, I have been looking in the js folder for the the document ready block in GB to add some js code, but I can't locate it.
Put this line inside the document ready block of your theme’s js file
Regards
Carsten
Hi there,
what code are you trying to add? If it's a jquery you can just wrap it like so:
jQuery( document ).ready( function( $ ) {
script in here
} );
And use the Hook Element - WP Footer Hook:
https://docs.generatepress.com/article/hooks-element-overview/
Hi David, yes it is a jQuery, and I had tried to put it in a custom hook, but it doesn’t kick in.
I have posted this issue before but wanted to try another approach, copying the code directly in a js file, because the custom hook option in GP shows no effect.
<script type=”text/javascript”>
jQuery(document).ready(function() {
jQuery(‘#send_message_form’).submit( function() {
jQuery(‘#subject’).val(“Some message subject”);
});
});
</script>
Ps. I do not receive email on replies, despite this option is checked?
Can you link me to the article where it explains adding this code?
Can you add the script to the WP_Footer hook and set the display rules to the entire site?
No difference, could you please check if the wrapping is correct?
The only thing that looks a little odd are the single and double quotes. Remove them and replace them manually.
Hi David, just a status update, as it turns out, the jQuery I tried to add, only works with the Buddypress Legacy template, not Nouveau. So no wonder I couldn’t make it work.
Thanks for your efforts
Regards
Carsten
Haha - awesome - glad you found out the reason :)
Just a quick question, I am going to insert code into the head section of my site, is the Header element the right place for Header Scripts like this (for PWA icon support on iOS)?
<!-- place this in a head section -->
<link rel="apple-touch-icon" href="touch-icon-iphone.png">
<link rel="apple-touch-icon" sizes="152x152" href="touch-icon-ipad.png">
<link rel="apple-touch-icon" sizes="180x180" href="touch-icon-iphone-retina.png">
<link rel="apple-touch-icon" sizes="167x167" href="touch-icon-ipad-retina.png">
Regards
Carsten
The Hook Element is the right place for adding scripts / meta etc.
Select the wp_head hook in the element.
Hi Dave thanks for your quick reply, I had choose Header element instead of Hook > wp_head...
Some more info on the hooks element can be found here, in case you need it:
https://docs.generatepress.com/article/hooks-element-overview/