1

The WordPress theme I am using deregisters the jQuery and jQuery UI libraries and registers google-hosted versions instead of the libraries from wp-includes. Here is the code in `functions.
UPDATE:

function w3t_add_scripts() {
    $options = get_option('lollipop');
    global $data; //get theme options

    wp_enqueue_script('jquery');    
    wp_enqueue_script('jquery-ui');

    // Site wide js
    wp_enqueue_script('modernizr', get_template_directory_uri() . '/js/modernizr.min.js');
    wp_enqueue_script('customscript', get_template_directory_uri() . '/js/customscript.js');

    //Slider
    if($options['w3t_featured_slider'] == '1') {
    //  if(is_front_page() || is_page()) {
            wp_enqueue_script('cslider', get_template_directory_uri() . '/js/jquery.cslider.js');
    //  }
    }

    //Lightbox
    if($options['w3t_lightbox'] == '1') {
        wp_enqueue_script('prettyPhoto', get_template_directory_uri() . '/js/jquery.prettyPhoto.js');
    }
}
add_action('wp_enqueue_scripts','w3t_add_scripts');

That's how the entire function looks like now. i did what you suggested, but it's not loading the jquery or jquer-ui files

  • what do you mean by local version? – JMau Aug 17 '13 at 21:02
  • already available version in wordpress, there are right ? – Ayaz Malik Aug 17 '13 at 21:03
  • just remove all code then – JMau Aug 17 '13 at 21:07
  • 3
    Get a better Theme. This one is _doing_it_wrong() at least two major ways (not wrapping the enqueues in a callback, and deregistering core-bundled scripts), and I'm guessing those aren't its only two issues. – Chip Bennett Aug 18 '13 at 0:44
  • 1
    Per usual I agree with @ChipBennett you should get a better theme. That said I think part of your problem is that jquery-ui is the wrong handle to use. WordPress has the individual parts of the jquery-ui library separated. You need to add 'jquery-ui-core' and whatever other components you need. See the whole list at codex.wordpress.org/Function_Reference/… . Your theme could be doing other things that are interfering with what you are trying to do. – JPollock Aug 19 '13 at 0:03
2

If that code is written into the theme just like that-- that is, it isn't hooked into wp_enqueue_scripts like is should be-- then you can't "undo" this without hacking the theme.

I should add that if the theme has this code in functions.php just like that and not hooked then the theme is doing it wrong and if you had debugging enabled you'd see this:

Notice: wp_deregister_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. Please see Debugging in WordPress for more information.

You need to remove the code and (possibly) add this:

function enqueue_scripts_wpse_110500() {
  wp_enqueue_script('jquery-ui');
}
add_action('wp_enqueue_scripts','enqueue_scripts_wpse_110500');

With that code, WordPress should load jQuery itself automatically.

I would advise against using a theme that is doing something so fundamental as this incorrectly. No telling what other sloppiness there is in the theme.

  • hello, thanks . i updated the answer as per your answer. but it still doesn't includes jquery please see updated question – Ayaz Malik Aug 18 '13 at 10:56
  • There is something happening in code not posted. This should not be that hard. – s_ha_dum Aug 18 '13 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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