Hi,
I need to add a script element (<script src="js/my.js"></script>
) to the <head>
of an individual page (my.html) of my site.
I don’t want this in the head of every page – just my.html.
What would be your recommended (child theme) approach for this?
Many Thanks.
Hi!
Yes, we definitely recommend child theme otherwise your changes will be overwritten with each update – http://kriesi.at/documentation/enfold/using-a-child-theme/
Then add my.js file into js folder in your child theme and then add following code to Functions.php file of your child theme
function my_custom_script() {
if(is_page(59)){
wp_enqueue_script( 'my-js', get_stylesheet_directory_uri() . '/js/my.js', array(), '1.0.0', true );
}
}
add_action( 'wp_enqueue_scripts', 'my_custom_script' );
then replace 59 with the ID of your page
Regards,
Yigit
Thanks Yigit – seems I also need to add <body onload="myScript()">
of this page. Any way to do this with a function?