WordPress.org

Ready to get started?Download WordPress

Forums

Load built-in jQuery on admin panel only (14 posts)

  1. MultiformeIngegno
    Member
    Posted 2 years ago #

    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! :)

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    What hook are you using to enqueue your script?

  3. MultiformeIngegno
    Member
    Posted 2 years ago #

    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..

  4. esmi
    Forum Moderator
    Posted 2 years ago #

    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?

  5. MultiformeIngegno
    Member
    Posted 2 years ago #

    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..

  6. esmi
    Forum Moderator
    Posted 2 years ago #

    OK - let's got back a few steps... what are you trying to do?

  7. MultiformeIngegno
    Member
    Posted 2 years ago #

    :P

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

  8. esmi
    Forum Moderator
    Posted 2 years ago #

    Why?

  9. MultiformeIngegno
    Member
    Posted 2 years ago #

    Because I don't want to load more than 50Kb of stuff without need. :)

  10. esmi
    Forum Moderator
    Posted 2 years ago #

    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.

  11. MultiformeIngegno
    Member
    Posted 2 years ago #

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

  12. esmi
    Forum Moderator
    Posted 2 years ago #

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

  13. MultiformeIngegno
    Member
    Posted 2 years ago #

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

  14. esmi
    Forum Moderator
    Posted 2 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.