My wordpress site is a bit heavy to download. On the frontend, its including jquery unnecessarily. In my firebug it looks like:
jquery.js?ver=1.3.2
and
jquery.form.js?ver=2.02m
I don’t need these to be included for me.
I’m happy for them to remain in the wp-admin, but I’d like them not to load on the frontend.
I have found the file I think which is loading them in wp-includes/script-loader.php
but I’m not sure what to uncomment out or what to do to remove it completely for the front.
Is there a way to do this, removing jquery without ruining the back end?
The correct method to completely remove a style or script is to dequeue it and deregister it. You should also note that front end scripts are handled through the
wp_enqueue_scripts
hook while back end scripts are handled through theadmin_enqueue_scripts
hook.So with that in mind, you can do the following
EDIT 1
This has been fully tested on WordPress version 4.0 and working as expected.
EDIT 2
As proof of concept, paste the following code in your functions.php. This will print a success or failure message in the head of your site, back end and front end
JQuery may be being added by your theme. If your theme is adding it properly, it should be using the
wp_enqueue_script()
function. To remove JQuery, simply use thewp_deregister_script()
function.Removing JQuery for your whole site might cause some unintended consequences for your admin section. To avoid removing JQuery on your admin pages, use this code instead:
Now only pages that are not admin pages will run the
wp_deregister_script()
function.Add this code to the functions.php file in your theme directory.
All the other solutions are now out of date as of wordpress 3.6
WordPress adds this jQuery call via a template tag named
<?php wp_head(); ?>
, which appears in most themes, and is necessary for some plugins to work.It could be annoying, not only because of loading, but because it might kill previously loaded jQuery, and might even get in the way of some plugins who try to load jQuery as well.
The quick fix is openning up the file header.php in your theme’s directory, and adding:
right before
Or just combine them both into:
A more technical explanation could be found here
It’s correct – removes jquery library js. Code from other answers removes all js (even js that your installed plugins adds)
Tested on 4.3.1
WordPress 5 and above (Tested)
Remove the default jquery and add your jquery from folder or from CDN. Use only one, ‘local’ or ‘cdn’
Syntax
Look into your theme files.
may include the .js files.
In most of the WordPress theme. jQuery used on admin panel (wp-admin) OR jQuery used in product page. to speed up. this will work. Tested on WP 5.0
jQuery only load if admin is logged in or its product page (its doesn’t matter user logged in or not on product page. (jQuery load on product page))
Look in the source of your rendered page; WordPress often includes jQuery by default when
<?php wp_head(); ?>
is called in header.php, so you may stil see jQuery included in your site.If you remove
<?php wp_head(); ?>
in header.php, you might loose other plugin functionality, as many plugins “hook” into WordPress at that point.But including jQuery isn’t that big of a deal. It’s small and WordPress depends on it for some things.
I was able to shave 2.2 seconds off my “Events” page load speed by de-registering jQuery. jQuery is a nice to have but in my opinion page speed is so much more important.
You’ll never have a user hang around for more than 5 seconds so if jQuery is causing you performance problems, then I say get rid.
jQuery.js is just 15KB if you’re using the minified version, and these would be totally absent if you were using a theme that doesn’t require it.
You should probably look for a lightweight theme without jQuery instead of hacking it and then seeing the theme break in several places because they’re looking for those js files.