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:
- Stylesheets:
wp_enqueue_style()
- Scripts:
wp_enqueue_script()
So, for a Plugin-enqueued stylesheet, named foobar.css
, you’d need to look in the Plugin files for calls to wp_enqueue_style()
, then note the name of the callback function it is called within. Then, find the add_action()
call that references that callback function. e.g.:
add_action( 'wp_head', 'pluginname_enqueue_styles' );
Once you’ve found that call, you can override it yourself, using remove_action()
:
remove_action( 'wp_head', 'pluginname_enqueue_styles' );