Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

try add_action('wp_enqueue_scripts', 'my_slider_scripts')

the hook doesn't have a dash. It's an underscore.

share|improve this answer
    
i fixed the typo and the scripts are still not being included in the page. Is there something that needs to be added to the page template file? –  micahmills Jul 25 '12 at 1:37
    
You have wp_head() and wp_footer() calls in your header and footer templates, right? –  Joseph Jul 25 '12 at 2:33
    
yes! To be honest I moved onto another solution for this. It was taking to much time. Thanks for your help though. –  micahmills Jul 25 '12 at 22:08

(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');  
share|improve this answer

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' );



    ?>
share|improve this answer
    
init should not be used to enqueue scripts, always use wp_enqueue_scripts. –  Milo Mar 18 at 17:39
    
In my answer I show you why and in which situation you should use init hook. –  WpMania.Net Mar 19 at 8:24
    
In your answer you give no compelling reason why you should use the wrong hook, and how it would possibly fix the issue. –  Milo Mar 19 at 14:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.