How can I remove jquery from the frontside of my WordPress? How can I remove jquery from the frontside of my WordPress? wordpress wordpress

How can I remove jquery from the frontside of my WordPress?


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 the wp_deregister_script() function.

wp_deregister_script('jquery');

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:

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

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.


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 the admin_enqueue_scripts hook.

So with that in mind, you can do the following

add_filter( 'wp_enqueue_scripts', 'change_default_jquery', PHP_INT_MAX );function change_default_jquery( ){    wp_dequeue_script( 'jquery');    wp_deregister_script( 'jquery');   }

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

add_action( 'wp_head', 'check_jquery' );add_action( 'admin_head', 'check_jquery' );function check_jquery() {    global $wp_scripts;    foreach ( $wp_scripts->registered as $wp_script ) {        $handles[] = $wp_script->handle;     }    if( in_array( 'jquery', $handles ) ) {        echo 'jquery has been loaded';    }else{        echo 'jquery has been removed';    }}


All the other solutions are now out of date as of wordpress 3.6

add_filter( 'wp_default_scripts', 'change_default_jquery' );function change_default_jquery( &$scripts){    if(!is_admin()){        $scripts->remove( 'jquery');        $scripts->add( 'jquery', false, array( 'jquery-core' ), '1.10.2' );    }}