I’ve been working on performance of my site using YSLOW, and noticed that WordPress it outputting things in my document head that I know I don’t need.
For example, I’m already calling jQuery 1.9 from the Google CDN, so I don’t need the call to jQuery in wp-includes.
Also, a plugin is including a stylesheet which I don’t need (because I’m overwriting 99% of those styles anyway in my theme), so I’d like to get rid of that call also.
So how do I edit what is being output by the wp_head()
function, whether WordPress is putting it there (like the wp-includes
jQuery call) or whether a plugin is putting it there (like the stylesheet call)?
First: don’t enqueue custom versions of WordPress core-bundled scripts, including (and especially) jQuery.
Second, to answer your question: those Plugin scripts and stylesheets are enqueued, using
add_action()
, via a callback hooked into one of the following action hooks:wp_head
wp_enqueue_scripts
wp_print_scripts
wp_print_styles
(There are others, but those are the most likely.)
Inside the callback, the following functions are used to enqueue:
wp_enqueue_style()
wp_enqueue_script()
So, for a Plugin-enqueued stylesheet, named
foobar.css
, you’d need to look in the Plugin files for calls towp_enqueue_style()
, then note the name of the callback function it is called within. Then, find theadd_action()
call that references that callback function. e.g.:Once you’ve found that call, you can override it yourself, using
remove_action()
:I don’t agree that overriding default versions with a CDN-hosted version is a bad practice. The onus is on you, however, to ensure you’re using a version which all of your plugins are compatible with. Be sure to test thoroughly.
To override the default jQuery with the CDN version, add something like this to your
functions.php
: