Can’t see why my scripts aren’t loading when I register and enqueue them

I’m trying to replace “hardcoded” calls in my header.php by registering and enqueueing them in functions.php. JQuery 1.8.3 loads as desired, but the other scripts don’t. Here’s what I’m using:

function puckpros_load_my_scripts() {  
    wp_deregister_script( 'jquery' );  
    wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js');  
    wp_enqueue_script('jquery');  
    wp_register_script('menu', get_stylesheet_directory_uri().'/js/menu.js', array('jquery') );  
    wp_enqueue_script('menu');
    wp_register_script('kwicks', get_stylesheet_directory_uri().'/js/jquery.kwicks.js', array('jquery') );  
    wp_enqueue_script('kwicks');
    wp_register_script('equalheights', get_stylesheet_directory_uri().'/js/jquery.equalheights.js', array('jquery') );  
    wp_enqueue_script('equalheights');
}  

add_action('wp_enqueue_scripts', 'puckpros_load_my_scripts'); 

It’s a child theme, so I’m using get_stylesheet_directory_uri() and the paths to the files are correct.

Read More

I’m sure it’s something simple, but I can’t see what I’m doing wrong.

Thanks.

EDIT

As suggested below by Chip, I changed my functions.php to eliminate the call to jquery and remove the register calls. I now have:

function puckpros_load_my_scripts() {  

     wp_enqueue_script('kwicks', get_stylesheet_directory_uri().'/js/jquery.kwicks.js', array('jquery') );

     wp_enqueue_script('equalheights', get_stylesheet_directory_uri().'/js/jquery.equalheights.js', array('jquery') );

     wp_enqueue_script('wslaunch', get_stylesheet_directory_uri().'/js/wsLaunch.js', array('jquery') );
}  

add_action('wp_enqueue_scripts', 'puckpros_load_my_scripts'); 

But my script equalheights won’t execute, tho it does if I load in directly in the header like this:

<script type="text/javascript" src="<?php bloginfo('stylesheet_directory');?>/js/jquery.kwicks.js"></script>
<script type="text/javascript" src="<?php bloginfo('stylesheet_directory');?>/js/jquery.equalheights.js"></script>
<script type="text/javascript" src="<?php bloginfo('stylesheet_directory');?>/js/wsLaunch.js"></script>

Now I’m stumped again. I’d like to “do it right” and enqueue, but I can’t get it to work.

Thanks for any help.

Related posts

1 comment

  1. You can’t (well, you can, but you’ll likely experience dependency issues such as this one) deregister a script at wp_enqueue_scripts that was registered earlier, and already used as a dependency.

    The best solution is to get rid of the custom jquery code, and just rely on core-bundled jQuery. (You’re going to break a LOT of things loading a non-core-bundled version of jQuery; especially a version that is older than the core-bundled version.)

    function puckpros_load_my_scripts() {  
        wp_enqueue_script('menu', get_stylesheet_directory_uri().'/js/menu.js', array('jquery') );  
        wp_enqueue_script('kwicks', get_stylesheet_directory_uri().'/js/jquery.kwicks.js', array('jquery') ); 
        wp_enqueue_script('equalheights', get_stylesheet_directory_uri().'/js/jquery.equalheights.js', array('jquery') ); 
    }  
    add_action('wp_enqueue_scripts', 'puckpros_load_my_scripts'); 
    

    Note: for simplicity’s sake, I’ve eliminated the wp_register_script() calls; they’re redundant in this case.

    But if you absolutely must deregister core-bundled jQuery to register your own version, try doing it at init.

    function pleasedonotderegistercorejquery() { 
        wp_deregister_script( 'jquery' );  
        wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js');  
        wp_enqueue_script('jquery');  
    }
    add_action( 'init', 'pleasedonotderegistercorejquery' );
    

Comments are closed.