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.
- Edit the functions.php theme functions file located in the directory of the active WordPress theme.
- Add in the following code into the file:
if ( !is_admin() ) wp_deregister_script('jquery');
- Save the file and it’s done.
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.
- Edit the header.php header file located in the directory of the WordPress active theme.
- Search for the following line of code:
<?php wp_head(); ?>
- Before the line, add the following line of code:
<?php wp_deregister_script('jquery'); ?>
It should look like this after modification:
[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]<?php wp_deregister_script('jquery'); ?>
<?php wp_head(); ?> - Save the file.
Recent Articles
- How To Download HBO Shows On iPhone, iPad Through Apple TV App
- Windows 10 Insider Preview Build 19025 (20H1) for PC Official Available for Insiders in Fast Ring – Here’s What’s News, Fixes, and Enhancement Changelog
- Kaspersky Total Security 2020 Free Download With License Serial Key
- Steganos Privacy Suite 19 Free Download With Genuine License Key
- Zemana AntiMalware Premium Free Download For Limited Time