0

I want to use jquery in my admin side programming but it seems there's no jquery loaded in the page at all and it load only at main website! Has my wordpress any problem which can't load jquery or I should do something extra to do it. However I put this code in function.php, but it not works:

if(is_admin()){        
    function load_admin_script(){
        wp_enqueue_script('jquery_script', "/wp-includes/js/jquery/jquery.js");
    }
    add_action('admin_enqueue_scripts','load_admin_script');

 } 
2
  • WordPress should automatically load jQuery for wp-admin, so you shouldn't need extra CODE for that. Did you check your browser's developer console (right click -> inspect -> console)? Perhaps there is a javascript error or some other theme / plugin is removing jQuery.
    – Fayaz
    Feb 21, 2017 at 14:23
  • But why jQuery.js is second time load WordPress default load this js. so check why default js is not load. May 18, 2018 at 4:30

2 Answers 2

2

If you want to load Jquery, wordpress already provides a handler for it (its also the one in /wp-includes/js/jquery/jquery.js):

    function load_admin_script(){
            wp_enqueue_script('jquery');
    }
    add_action('admin_enqueue_scripts','load_admin_script');

note that the jQuery in WordPress runs in noConflict mode.

4
  • Thanks @David, but where should I put this? I put it in function.php of my child theme but it not works. Should I make a plugin to do this? Feb 21, 2017 at 7:57
  • How are you checking if its loading? i just did an update to my answer
    – David Lee
    Feb 21, 2017 at 13:18
  • if you use admin_enqueue_scripts hook, do you really need if(is_admin()) check?
    – Fayaz
    Feb 21, 2017 at 13:57
  • oh true, i guess it was pretty late for me
    – David Lee
    Feb 21, 2017 at 14:01
0

You can use add_action hook to load your jquery in your admin area like below code.

<?php 
add_action( 'admin_enqueue_scripts', 'load_jquery' );
function load_jquery() {
    wp_enqueue_script('load_js',YOUR PATH.'/js/jquery.js');
} 
?>
1
  • So what's the deffrence between mine and yours? Feb 21, 2017 at 7:55

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.