Support » Fixing WordPress » Load built-in jQuery on admin panel only

  • Hi! 🙂
    I created a theme for WP 3.3.1. Everything works properly, except that I’d like to load jQuery on admin panel only (not “outside”).
    This is because my websites doesn’t need it, I just need it to run the admin pages (media functions to edit the images, the admin menu to work, the wp_nav_menu organization in admin, etc…).

    I’d avoid to deregister the built-in script and register another one.. I’d just specify that it should run on admin panel only…

    How can I obtain that?

    Thanks in advance! 🙂

Viewing 13 replies - 1 through 13 (of 13 total)
  • esmi

    (@esmi)

    Forum Moderator

    What hook are you using to enqueue your script?

    Ahem.. actually I don’t know.. I presume it’s included in <?php wp_head ?> because I don’t call it. It’s the already built-in jQuery..

    esmi

    (@esmi)

    Forum Moderator

    jQuery is built into WordPress but what are you using to enqueue your script? I’m assuming you are trying to load a script on the admin side only, yes?

    Yes! I created a child theme starting from the TwentyTen theme.. Unfortunately I don’t know where jQuery is called in the theme! I just know that it’s present in the HTML of my website, so it’s somewhere in wp_head. I looked in functions.php, header.php, index.php, footer.php but there’s no call to jQuery… can’t find it but it’s in my website html.. and I want it only loaded in admin panel. 🙂

    I presume it’s called with <?php wp_enqueue_script(‘jquery’); ?>, but can’t find it..

    esmi

    (@esmi)

    Forum Moderator

    OK – let’s got back a few steps… what are you trying to do?

    😛

    Have jQuery only loaded in admin panel. NOT in posts/pages. 🙂

    esmi

    (@esmi)

    Forum Moderator

    Why?

    Because I don’t want to load more than 50Kb of stuff without need. 🙂

    esmi

    (@esmi)

    Forum Moderator

    Then you need to de-register jQuery based on the is_admin() conditional but, be warned, many themes and/or plugins may not work correctly if you disable jQuery on the front end of your site.

    No problem, I don’t use plugins. 🙂
    is_admin works for admin only or for editors/authors too..?

    esmi

    (@esmi)

    Forum Moderator

    `is_admin() = is this the WP admin area (ie the back end of a site).

    So this would work..?
    <?php
    if ( ! is_admin() ) {
    wp_enqueue_script(‘jquery’);
    } else { }
    ?>

    esmi

    (@esmi)

    Forum Moderator

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Load built-in jQuery on admin panel only’ is closed to new replies.