Home of a med student who likes to manage websites and talk tech!

Remove unwanted WordPress header elements

with 287 comments

WordPress LogoI was performing a bit of optimization on one of my WordPress blogs and wanted to clean up the header. The default installation of WordPress adds quite a bit up there and this bloat can be compounded by a theme’s own customizations. After quite a bit of searching around Google, I came up with a clean solution. Here is what I did to help de-clutter my theme’s header.

In addition to custom Javascript and CSS calls that may clutter your theme’s header.php file, you may find some other elements whose features you will never use or could do without. However, these elements usually only appear when viewing your pages through your browser, because activated plugins will automatically insert them via PHP. Take, for example, WP-PageNavi. This is a great plugin for placing numbered page links in your WordPress blog, but it inserts a call to its own stylesheet. Being the optimization junkie that I am, it would be better for me to just combine WP-PageNavi’s stylesheet with my theme’s stylesheet so a single CSS file loads all of the styles. The problem is getting rid of WP-PageNavi’s call to its own stylesheet without deactivating the plugin altogether.

Many of these header insertions are being called by the wp_head() hook. Look in your theme’s header.php file and you will see it there. If you think that simply removing the hook will eliminate these extra insertions, you are correct, but it doesn’t come without consequences. Doing so may completely cripple the functionality of your blog because there are other necessary insertions that are required to make your theme work properly. You can, however, disable individual insertions without removing the wp_head() hook, which gives you more control.

In order to achieve removal of plugins hooking into wp_head() you will need to look at that plugin’s main PHP file. Look for functions that look like this:

add_action('wp_head', 'plugin_function_here');

Adding the following line to your theme’s functions.php file and saving it will disable that insertion via wp_head():

remove_action('wp_head', 'plugin_function_here');

Reload a page in your web browser and view the source to see the changes. Quite self-explanatory and simple, isn’t it? Just be careful of what you remove.

There are unique cases where forcing a remove_action from wp_head() does not work. In the case of WP-PageNavi, there is no explicit action being added to wp_head(), but it will still load its own stylesheet. If you look at wp-pagenavi.php you will notice the ‘Enqueue PageNavi Stylesheets’ function that inserts the stylesheet via a wp_print_styles action:

add_action('wp_print_styles', 'pagenavi_stylesheets');

To stop WP-PageNavi’s stylesheet from being called in the header, all you need to do is add the following to your theme’s functions.php file:

remove_action('wp_print_styles', 'pagenavi_stylesheets');

By now you should be noticing a trend. Find the function, then remove the function. Here are some other elements that you can remove that are in direct reference to wp_head(). Note that you should only disable these features if you do not use them.

// Really Simple Discovery
remove_action('wp_head', 'rsd_link');
// Windows Live Writer
remove_action('wp_head', 'wlwmanifest_link');

You can take things a bit further as I have done. I noticed that my theme calls for jQuery Javascript through wp_head() plus a few other Javascript files outside of wp_head(). Again, I was looking at a way of possibly combining and compressing my theme’s Javascript, but how would I disable jQuery loading through wp_head()? I could not find a function reference that would allow me to remove it and trying remove_action('wp_head', 'jquery'); didn’t work. I did find that wp_deregister_script('jquery'); could work perfectly. However, if placed in your theme’s functions.php file, the WordPress Dashboard admin area would become seriously crippled! No longer would the fancy drop-down menus work and various other features stopped working properly all of a sudden. Obviously, the admin area requires jQuery (duh!), so I had to remove the entry from my theme’s functions.php file. Being inquisitive as I am, I placed wp_deregister_script('jquery'); in my theme’s header.php file instead and, to my surprise, doing this disabled jQuery from loading in the theme yet allowed the admin area to retain full functionality.


Be aware that my theme still utilizes jQuery. It is just that I have chosen to pack all of my Javascript together and call for it through a static URL within script tags.

I hope this post is helpful to persons who are interested in gaining more control over their theme’s header and reducing all of the clutter. Please be careful of what you edit and, of course, have fun with WordPress!

About these ads

Written by falcon1986

15 July, 2009 at 10:25 AM

287 Responses

Subscribe to comments with RSS.

  1. I constantly spent my half an hour to read this website’s articles
    or reviews daily along with a mug of coffee.

    criminal bail

    25 September, 2014 at 9:10 PM

  2. Fine way of describing, and pleasant piece of writing to take
    data regarding my presentation focus, which i am going to convey
    in institution of higher education.


    26 September, 2014 at 1:08 AM

  3. Hello there, just became aware of your blog through
    Google, and found that it is really informative.
    I’m gonna watch out for brussels. I will appreciate if you continue
    this in future. A lot of people will be benefited from your writing.

    hartford ct directions

    27 September, 2014 at 12:37 AM

  4. Hi there friends, how is all, and what you want to say concerning this paragraph, in my view its truly awesome in support of me.

    ip phone system New York City

    27 September, 2014 at 10:13 AM

  5. Great delivery. Great arguments. Keep up the amazing spirit.

    top voip service New York City

    27 September, 2014 at 4:54 PM

  6. So spending a large amount of damage caused, and the quality of roofing.

    Some roofing jobs are costly capitol roofing as they need more equipments and experts on site.
    We have had a few leaks and they’ve fixed most of them are in the optimum
    position for the reception of sunlight and rainwater.
    Check capitol roofing with your local building supplies store or flooring materials distributor.
    Utilizing light colored corrugated roofing materials and related products,
    such as replacing shingles that fall off, or ones that no
    longer are working correctly.

    rain gutters fort collins

    28 September, 2014 at 12:53 AM

  7. We stumbled over here different page and thought I may as well check things out.

    I like what I see so i am just following you. Look forward to looking into
    your web page again.

  8. fantastic points altogether, you just received
    a new reader. What could you suggest in regards to your put up that you simply made some
    days in the past? Any certain?

  9. I like the helpful information you provide in your
    articles. I will bookmark your blog and check again here
    frequently. I’m quite certain I’ll learn lots of new stuff right here!
    Good luck for the next!

  10. Hey there! I know this is somewhat off topic but I was wondering
    if you knew where I could locate a captcha plugin for my comment form?
    I’m using the same blog platform as yours and I’m
    having problems finding one? Thanks a lot!

  11. I’m gone to inform my little brother, that he should also go to see this weblog on regular basis to take updated from
    most up-to-date news.

    what is a surety bail bond

    30 September, 2014 at 7:00 PM

  12. Hello, everything is going nicely here and ofcourse every one is
    sharing data, that’s genuinely good, keep
    up writing.

  13. Please let me know if you’re looking for a article author for
    your site. You have some really great articles and I
    think I would be a good asset. If you ever want to take some of the load off, I’d absolutely love
    to write some content for your blog in exchange for a link back to mine.
    Please blast me an e-mail if interested. Many thanks!

  14. Nice answers in return of this difficulty with real arguments and explaining the whole thing about that.

    turmeric before surgery

    1 October, 2014 at 2:04 AM

  15. Hey! I could have sworn I’ve been to this site before but after reading through some of
    the post I realized it’s new to me. Anyways, I’m definitely
    glad I found it and I’ll be book-marking and checking back often!

  16. What’s up, yup this post is in fact pleasant and I
    have learned lot of things from it on the topic of blogging.

    anytime bail bonds

    1 October, 2014 at 5:38 PM

  17. Hi there i am kavin, its my first time to commenting anyplace, when i read this post i thought i could also create comment
    due to this brilliant piece of writing.

    bail bonds brooklyn ny

    1 October, 2014 at 11:49 PM

  18. Hello my friend! I wish to say that this article is amazing,
    great written and include almost all vital infos.
    I would like to see more posts like this .

    Stevia Warnings

    2 October, 2014 at 12:36 AM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: