jQuery, WordPress and your functions.php

It’s always interesting running ySlow on a website you are working on, getting that ‘warm fuzzy feeling’ when you finally get that ‘A’. I noticed while using it on nooshu that jQuery was being included twice. Version 1.4 by me in the footer.php and version 1.3.2 being included by a plug-in (or WordPress itself). Not Good. The user gets an extra 40Kb download and an added HTTP request.

A quick way to fix this is to add this to your functions.php file (located in the theme directory). The admin section will still be able to use it’s own version of jQuery due to the if statement.

1
2
3
if(!is_admin()){
    wp_deregister_script('jquery');
}

If you don’t have a functions.php file you can create a new one and paste that code inside. While in there you may also want to include this:

1
remove_action('wp_head', 'wp_generator');

That will remove your current WordPress version from your ‘head’ tag in your templates. Not a big issue but could be useful information to a malicious individual.

For more information on both functions in the WordPress codex see remove_action and wp_deregister_script

Leave a Comment

Your email will not be published. Required fields are marked *.