Mar 25, 2013
Tip and Trick Editorial

How to Deregister and Remove jQuery from WordPress Header

The multi-browser JavaScript library designed to simplify the client-side scripting of HTML, jQuery, is one of main script used by WordPress.

By default, WordPress loads a version of jQuery which comes packaged with WordPress core files through wp_head(). However, some theme developers or plugin developers may also knowingly or unknowingly load the same version or different version of jQuery through the theme or plugin.

The existence of more than one version of jQuery potentially breaks the working of Javascript used in theme or plugin, kill previously loaded jQuery and increases the page loading time due to calls to redundant jQuery. In most cases, it’s unnecessary and unrecommended to even have more than one declaration to load the jQuery.

For webmasters who want to take control of how, what and when jQuery is loading in WordPress, it’s possible to stop WordPress from loading the jQuery automatically.

Follow the steps below to deregister jQuery from automatically inserting itself in WordPress header. Note that this step deals with jQuery that been loaded by WordPress core, but not of those added by plugins and/or themes.

  1. Edit the functions.php theme functions file located in the directory of the active WordPress theme.
  2. Add in the following code into the file:

    if ( !is_admin() ) wp_deregister_script('jquery');

    Deregister WordPress jQuery

  3. Save the file and it’s done.
[note color=”#FFCC00″]Note that WordPress backend wp-admin also requires jQuery to work properly. So it’s important to ensure that jQuery continues to load for the WordPress dashboard and administration section.[/note]

Alternatively, it’s possible to insert a line of code right before wp_head() to deregister the jQuery. This method makes sure that only the frontend web pages served by the theme will have WordPress default jQuery disabled, and does not affect the backend admin section.

  1. Edit the header.php header file located in the directory of the WordPress active theme.
  2. Search for the following line of code:

    <?php wp_head(); ?>

  3. Before the line, add the following line of code:

    <?php wp_deregister_script('jquery'); ?>

    It should look like this after modification:

    <?php wp_deregister_script('jquery'); ?>
    <?php wp_head(); ?>

    Disable WordPress jQuery

    [note color=”#FFCC00″]Depending on the theme, you may not able to find the exact same line as above. Just look for wp_head(); which should be universally identical.[/note]
  4. Save the file.

Pin It on Pinterest

Share This

Share This

Share this post with your friends!