145 posts
  • 3 Years of Membership
  • Austria
  • Collector Level 1
  • Exclusive Author
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'); ?>
743 posts
  • Elite Author
  • Weekly Top Seller
  • Featured Item
  • Most Wanted Winner
+5 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
  • 3 Years of Membership
  • Austria
  • Collector Level 1
  • Exclusive Author
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

204 posts
  • Author Level 6
  • Featured Author
  • Freebie
  • 3 Years of Membership
+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
  • 3 Years of Membership
  • Austria
  • Collector Level 1
  • Exclusive Author
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.

3804 posts
  • Elite Author
  • Author Level 11
  • Trendsetter
  • 7 Years of Membership
+12 more
KrownThemes
says

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

145 posts
  • 3 Years of Membership
  • Austria
  • Collector Level 1
  • Exclusive Author
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
  • 3 Years of Membership
  • Austria
  • Collector Level 1
  • Exclusive Author
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.

3804 posts
  • Elite Author
  • Author Level 11
  • Trendsetter
  • 7 Years of Membership
+12 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..

210 posts Kita harus putus
  • Author Level 7
  • Featured Author
  • Beta Tester
  • Elite Author
+4 more
biyanpasau
says

Have you tried noConflict mode of jQuery?

by
by
by
by
by
by