I have been beating my head against this for a couple of hours now and can’t seem to figure it out. I am trying to enqueue a script into my page with the following code in my functions.php.
function my_slider_scripts() {
$scriptsrc = get_stylesheet_directory_uri().'/js/jquery.nivo.slider.pack.js';
wp_register_script( 'nivo-slider-pack', $scriptsrc );
wp_enqueue_script('nivo-slider-pack');
}
add_action( 'wp-enqueue_scripts', 'my_slider_scripts' );
I have looked at the codex and every tutorial I can find and nothing seems to make this work. I should mention I am using a child theme. Any ideas would be greatly appreciated.
try
add_action('wp_enqueue_scripts', 'my_slider_scripts')
the hook doesn’t have a dash. It’s an underscore.
(i deleted my old answer in favour of this)
You’re currently using
$scriptsrc = get_stylesheet_directory_uri().'/js/jquery.nivo.slider.pack.js';
maybe it should be
Here is some information for you so that you understand how things work with wp_enqueue_scripts.
You need to know the priority order for the wp_enqueue_scripts. Please check the below order of the hooks can be run……..
… and so one…..
So you see you can add it in the
init
hook and doing so it will be called as high priority than below the listing.If you found your files are not loading and you surely can use a high priority hook.
If you found your wp_enqueue_script is not being called, you can use this simple trick to get it work for your theme or plugin.