• Hi,

    Can somebody please tell me how to properly enqueue jQuery into my plugin code?
    I did this:

    if (is_admin()) add_action( "wp_enqueue_scripts", "my_jquery_enqueue", 11 );
    function my_jquery_enqueue() {
       wp_deregister_script( 'jquery' );
       wp_register_script( 'jquery', "http" . ( $_SERVER['SERVER_PORT'] == 443 ? "s" : "" ) . "://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js", false, null );
       wp_enqueue_script( 'jquery' );
    }

    And it didn’t work. I opened the console and got this message:
    GET https://localhost:8888/wordpress/wp-admin/jquery-1.10.2.min.map 404 (Not Found)

Viewing 2 replies - 1 through 2 (of 2 total)
  • Never, EVER, de-register core jQuery like that! It will cause all kinds of problems – including stopping some parts of the WordPress admin functioning properly (if at all).

    This is what I know about enqueueing scripts:

    Arguments:

    handle: a unique id for the script
    src: URL of the script
    deps: scripts that this script depends on
    ver: the version of the script
    in_footer: whether or not to load the script in the footer

    -You wrap a function around this and include it with an action

    Example:

    function coolslider_enqueue_script(){
       wp_enqueue_script(
        'my-coolslider',
        plugins_url( '/coolslider.js', __FILE__ ),
        array( 'jquery' ),
        '1.54',
        true
        );
    }
    add_action( 'wp_enqueue_scripts', 'coolslider_enqueue_script' );

    Hope this helps!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How do I enqueue jQuery in my plugin?’ is closed to new replies.