admin管理员组

文章数量:1287776

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');

 } 

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');

 } 
Share Improve this question asked Feb 21, 2017 at 6:11 Siamak FerdosSiamak Ferdos 4831 gold badge6 silver badges8 bronze badges 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 Commented 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. – Jignesh Patel Commented May 18, 2018 at 4:30
Add a comment  | 

2 Answers 2

Reset to default 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.

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');
} 
?>

本文标签: Admin side jquery is not loaded