scripts not enqueueing

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.

Related posts

Leave a Reply

3 comments

  1. (i deleted my old answer in favour of this)

    1. Check the Location … is the Nivo Slider in your theme / stylesheet folder or in the plugins directory?

    You’re currently using
    $scriptsrc = get_stylesheet_directory_uri().'/js/jquery.nivo.slider.pack.js';

    maybe it should be

    function my_scripts_method() {  
    wp_enqueue_script('my-script', plugins_url('/js/jquery.nivo.slider.pack.js', __FILE__), array('jquery'));
    } 
    
    add_action('wp_enqueue_scripts', 'my_scripts_method');  
    
  2. 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……..

    1. muplugins_loaded
    2. registered_taxonomy
    3. registered_post_type
    4. plugins_loaded
    5. sanitize_comment_cookies
    6. setup_theme
    7. load_textdomain
    8. after_setup_theme
    9. auth_cookie_malformed
    10. auth_cookie_valid
    11. set_current_user
    12. init
    13. widgets_init
    14. register_sidebar
    15. wp_register_sidebar_widget
    16. wp_default_scripts
    17. wp_default_stypes
    18. admin_bar_init
    19. add_admin_bar_menus
    20. wp_loaded
    21. parse_request
    22. send_headers
    23. parse_query
    24. pre_get_posts
    25. posts_selection
    26. wp
    27. template_redirect
    28. get_header
    29. wp_head
    30. wp_enqueue_scripts
    31. wp_print_styles
    32. wp_print_scripts

    … 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.

        <?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( 'init', 'my_slider_scripts' );
    
    
    
        ?>