0
function dwwp_admin_enqueue_scripts_mlm() {
    wp_enqueue_style( 'dwwp-admin-css', plugins_url( 'css/admin-users.css', __FILE__ ) );
    wp_enqueue_script( 'admin-users', plugins_url( 'js/admin-users.js', __FILE__ ) );
    wp_enqueue_script( 'jquery', 'http://code.jquery.com/jquery-1.10.2.js' );
            wp_enqueue_script( 'jquery-ui', 'http://code.jquery.com/ui/1.10.4/jquery-ui.js' );
    wp_enqueue_style( 'jquery-style', 'http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css' );}
add_action( 'admin_enqueue_scripts', 'dwwp_admin_enqueue_scripts_mlm' );

2 Answers 2

0

No. As wordpress codex states, you should use jquery and other javascript files provided by them. As for css files I think you can use yours.

Please check this link( scroll down) for a list of already defined javascript files.

Also, you have to use local files as much as possible, unless you have no other way. So for example, if you have a js library, you should download it and include it in your theme/plugin files and not enqueue it using CDN or any other external link. Wordpress team will refuse to publish your theme/plugin if you include external js files without a good reason.

LE: for jquery-ui you only have to use this

 wp_enqueue_script( 'jquery-ui')

or add it as a dependency of your own script like this

wp_enqueue_script('my-script', 'url-to-scrip', array('jquery-ui'))
4
  • Yes Okay..now it's works fine.I downloaded jquery and make it offline
    – P. Sheth
    Sep 3, 2016 at 9:55
  • I guess you downloaded the css for jquery and not js files. As @toscho says, do not try to override already existing js files as you may end up in a conflict Sep 3, 2016 at 10:15
  • ohhk...i will try below solution
    – P. Sheth
    Sep 3, 2016 at 11:13
  • @P.Sheth why are you trying to add external jquery files? Sep 3, 2016 at 11:16
2
  1. Do not try to overwrite the libraries (jQuery, jQuery UI) that are already provided by WordPress. This will either fail or result in conflicts with other plugins.
  2. Register your assets early, enqueue them by their handle only.
  3. Use the dependency parameter to make sure assets are loaded in the order you need.

So, you should do something like this:

if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) )
{
    add_action(
        'wp_loaded',
        function() {
            wp_register_script(
                'admin-users',
                plugins_url( 'js/admin-users.js', __FILE__ ),
                [ 'jquery-ui-core' ] // Let WP handle the rest.
            );
            wp_register_style(
                'jquery-style',
                'http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css'
            );
            wp_register_style(
                'dwwp-admin-css',
                plugins_url( 'css/admin-users.css', __FILE__ ),
                [ 'jquery-style' ]
            );
        }
    );
    add_action( 
        'admin_enqueue_scripts', 
        function() {
            wp_enqueue_script( 'admin-users' );
            // jquery-style will be loaded automatically.
            wp_enqueue_style( 'dwwp-admin-css' );
        }
    );
}
6
  • can you please show me how to add external jquery ?
    – P. Sheth
    Sep 3, 2016 at 10:41
  • @P.Sheth That's not possible in the admin area. WordPress will not allow it for good reasons: other plugins and WordPress itself will use the built-in one, and then you would have two versions of the same library loaded – debug hell. :)
    – fuxia
    Sep 3, 2016 at 11:18
  • For autocomplete suggestions i have to include jquery-1.12.4.js and jquery-ui.js. and i included but not working jquery properly.
    – P. Sheth
    Sep 3, 2016 at 11:28
  • @P.Sheth Use the built-in library jquery-ui-autocomplete. See wp-ncludes/script-loader.php for available libraries.
    – fuxia
    Sep 3, 2016 at 11:29
  • okay...and how to add this inbulit libraries?
    – P. Sheth
    Sep 3, 2016 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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