Skip to:
Content
Pages
Categories
Search
Top
Bottom

looking for some help with jquery, I’m really getting lost with this…


  • Sven Lehnert
    Participant

    @svenl77

    I tried to load jquery without generating conflicts, but I don’t get it.
    Could someone give me some advice?

    The jQuery is running, but it has conflicts with other jQuery on the site.
    I just need it for the backend and there just on one options page.
    I just found is_admin() to check if you are in the backend.

    or did I load the jQuery the wrong way?
    Here is what I’m doing at the moment.
    `
    if(is_admin()){
    add_action(‘init’, ‘load_js’);
    }
    function load_js() {
    ## wp_deregister_script(‘jquery’);
    wp_register_script(‘my-jquery’, ‘https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js’, false, ‘1.3.2’);
    wp_register_script(‘my-jquery-ui’, ‘https://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js’,false,’1.7.1′);
    wp_enqueue_script( ‘my-jquery’ );
    wp_enqueue_script( ‘my-jquery-ui’ );
    }
    `

    Please help!

Viewing 5 replies - 1 through 5 (of 5 total)

  • Boone Gorges
    Keymaster

    @boonebgorges

    jquery should already be loaded on all Dashboard panels, I think. You may still need to load jquery-ui. In that case, your method looks like it should work. The only possible snag I can see is that is_admin() might return false until after the ‘init’ action. In that case, try just doing
    `add_action(‘init’, ‘load_js’);`
    and move the admin check inside of the load_js() function:
    `function load_js() {
    if ( !is_admin() )
    return false;
    wp_register_script….`


    r-a-y
    Keymaster

    @r-a-y

    The bundled version of jQuery in WordPress is different than the stock jQuery library.

    WP adds a jQuery.noConflict() call. Most WordPress plugins rely on the WP version of jQuery. So by getting rid of the WP one, you’re going to be breaking some plugins.

    I’m pretty sure WP has jquery-ui in their includes folder.

    Check out this nifty codex article on wp_enqueue_script() to call a specific, bundled JS:
    https://codex.wordpress.org/Function_Reference/wp_enqueue_script


    Anonymous User 96400
    Inactive

    @anonymized-96400

    It should work, once you actually deregister jquery properly. At the moment it’s commented out, so you’re loading jquery twice, which might break things (also, not sure if init is the correct hook for that…).


    Anonymous User 96400
    Inactive

    @anonymized-96400

    Here’s what I use in my plugins. Well, something similar. I actually wrap it in a class and do some other things, but it should give you some ideas:

    `function load_scripts()
    {
    // no need to go on if it’s not a plugin page
    if( ! isset( $_GET ) )
    return;

    if( $_GET == EVENT_FOLDER )
    {
    wp_enqueue_script( … );
    }
    }
    add_action( ‘admin_print_scripts’, ‘load_scripts’ );`


    Sven Lehnert
    Participant

    @svenl77

    Hi guys,

    Thanks a lot for your help, with this knowledge, I found the way. Looks like it works now without bad site effects. :-)

    That’s what I do now.
    `
    function seopress_js() {

    if( ! isset( $_GET ) )
    return;

    if( $_GET == ‘seomenue’ || $_GET == ‘bp_seo_general_page’ || $_GET == ‘bp_seo_plugins’ ) {
    wp_enqueue_script(‘jquery’);
    wp_enqueue_script(‘jquery-ui-tabs’);
    }

    }
    `

    Thanks a lot, Sven

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘looking for some help with jquery, I’m really getting lost with this…’ is closed to new replies.
Skip to toolbar