145 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
LovelessDesign says

Hm I can’t get jquery to work without deregistering + registering it.

I tried building in the following code before wp_head();. Also tried it in functions.php
<?php wp_enqueue_script('jquery'); ?>
741 posts
  • Had an item featured on Envato Market
  • Won a Most Wanted contest
  • Has been part of the Envato Community for over 5 years
  • Has sold $40,000+ on Envato Market
+4 more
Orbital_Themes says

You don’t have to enqueue jQuery manually. Just mention it in the array of scripts required for your script file, WordPress will load it automatically. Also make sure that you have deleted all the code that deregisters and registers new version of jQuery.

145 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
LovelessDesign says

What do you mean by “Just mention it in the array of scripts required for your script file” Could you give some example code please

I have removed every code that deregisters and registers jQuery

203 posts
  • Has sold $40,000+ on Envato Market
  • Made it to the Authors' Hall of Fame
  • Contributed a free file of the month
  • Has been part of the Envato Community for over 2 years
+3 more
ikaruna says

hi,

make sure you add the proper hooks when to enqueue scripts, I have like this:

add_action('admin_enqueue_scripts', array($this, 'adminEnqueueScriptsHandler')); add_action("wp_enqueue_scripts", array($this, 'WPEnqueueScriptsHandler'));

basically first is for the admin, second is for the front-end (the $this is because mine is within a php class) jayc

145 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
LovelessDesign says

I’ve included my scripts like so:

function lld_enqueue_scripts() {
    if(!is_admin()) {

        wp_register_script('CssBrowserSelector', get_template_directory_uri() . '/js/css_browser_selector.js', array('jquery'), '1', FALSE ); 
        wp_register_script('superfish', get_template_directory_uri() . '/js/superfish.js', array('jquery'), '1', FALSE ); 
        ...
        wp_register_script('functionsJS', get_template_directory_uri() . '/js/functions.js', array('jquery'), '1.0', TRUE );

        wp_enqueue_script('jquery');
        wp_enqueue_script('CssBrowserSelector');
        wp_enqueue_script('superfish');
        ...
        wp_enqueue_script('functionsJS');    
    }
}  
add_action('wp_enqueue_scripts', 'lld_enqueue_scripts');      

Is there anything missing? I removed the deregistering and registering of jquery and jquery doesn’t work anymore.

3568 posts Ruben Bristian
  • Sells items exclusively on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Has been part of the Envato Community for over 6 years
+10 more
KrownThemes says

Why if(!is_admin()) { ?! :)

145 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
LovelessDesign says

Because it’s not needed in the dashboard. Many themes use this. But even if I remove it, it doesn’t work ;)

145 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
LovelessDesign says

Even if I just type

$(window).load(function () {
    alert("s");
}

in my functions.js it’s not loaded.

BUT it works when deregistering and registering jquery.

3568 posts Ruben Bristian
  • Sells items exclusively on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Has been part of the Envato Community for over 6 years
+10 more
KrownThemes says

Because it’s not needed in the dashboard. Many themes use this. But even if I remove it, it doesn’t work ;)

Whenever you enqueue a plugin in the functions.php, it will be outputted only in the front end. So that function is really useless..

Do you have wp_head() & wp_footer() in your theme? If WordPress is loading jQuery, it loads it in one of these two hooks and if you’re missing them you’re error is obvious..

205 posts
  • Has referred 100+ members
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+3 more
biyanpasau says

Have you tried noConflict mode of jQuery?

by
by
by
by
by
by