How to Clean Up WordPress Header

I started working with WordPress a couple of years ago when I decided to launch a couple of content sites. Since then I’ve been working a lot with WordPress and in general loving it.

Now I’m converting several client sites to WordPress and one of the things I usually start with is cleaning up a lot of code that I find useless in the document header. All of this code is inserted in the document page through the wp_head() hook.

And how do we clean up WordPress header? I choose to add a function to the WordPress theme being used. I could go with a plugin but I usually find it easier to go with this option. At the same time I’m learning more about how WordPress works.

What code can you remove? I will list first everything that will be removed and then show you how to add this code to a function. But when you apply this code to your theme confirm that you want to remove a specific function.

What we will be removing from wp_head()

  • Windows Live Writer
  • WordPress Generator
  • Really Simple Discovery
  • Shortlink
  • Emojis
  • Relational Links
  • Automatic Feed Links
  • REST API Links

Windows Live Writer

This is the code added by WordPress:

This is a function that displays a link to enable support to Windows Live Writer. I don’t need that on my sites so I’ll remove it. Be warned that we are only removing links from our document header. Function will not be disabled in WordPress.

To remove it use this code:

remove_action('wp_head', 'wlwmanifest_link');

WordPress Generator

This is the code added by WordPress:

This code places the WordPress version being used on your site. That information is not necessary to anyone else so I choose to remove it.

To remove it use this code:

remove_action('wp_head', 'wp_generator');


Really Simple Discovery

This is the code added by WordPress:


This code displays the link to the Really Simple Discovery service. I don’t integrate services on my sites so it’s safe to remove.

To remove it use this code:

remove_action('wp_head', 'rsd_link');



This is the code added by WordPress:


Adds rel=shortlink into head if a shortlink is defined.

To remove it use this code:

remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0 ); 



This is the code added by WordPress:



Emojis were added to WordPress in version 4.2.0. I never liked that we weren’t given an option to disable emojis on our site inside WordPress admin. So the best option is to disable them using these 2 lines of code that I’ve added to my function.

I never use those and they add too much code. To remove Emojis use this code:

   remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
   remove_action( 'wp_print_styles', 'print_emoji_styles' );


Relational Links

This is the code added by WordPress:


This code adds links to prev/next post in html.

To remove it use this code:

remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');


Automatic Feed Links

This is the code added by WordPress:


I like RSS feeds and use them many times including in my mail reader. By default WordPress adds some feeds and usually themes add main feed.

Themes add an action to functions.php so main feed link appears in document header.

add_theme_support( 'automatic-feed-links' );


I prefer to have a cleaner version of feed links because I don’t like feeds created by WordPress. And I can’t disable them one by one (only the main RSS feed) so I prefer to have them disabled in full.

Use this code to make sure all feeds are disabled:

remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'feed_links_extra', 3);


Don’t forget to add in the HTML link to the main feed. It’s very useful to help readers follow your content.


WordPress 4.4 was the first version to add support for REST API functionality. This is a game changer and important if you are going to use it. But if you don’t have intentions in using it you can remove all that extra code from the document header.

This is the code added by WordPress:


To disable it use this code:

remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );


WordPress also adds oEmbed discovery links with this code:


To disable it use this code:

remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );


And finally you should also disable link header to every page request:

remove_action('template_redirect', 'rest_output_link_header', 11, 0);


To make sure we remove everything related to oEmbed we should also use the following code:

remove_action( 'wp_head', 'wp_oembed_add_host_js' );
remove_action('rest_api_init', 'wp_oembed_register_route');
remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10);


In this final code oEmbed results are not filtered, oEmbed REST API route is removed and oEmbed-specific javascript is removed from wp-footer. Example:


I want to warn you that if you are using REST API then don’t use this code to disable it.

Create a Function

Start by opening your functions.php (always do a backup first of the file that you are going to work on). My function will be called wdv_cleanup. We are going to hook it to after_setup_theme action. This action is one of the first actions to be executed on a page load and it’s used to perform the basic setup for a theme.

Add all of these options combined into this new function:

function wdv_cleanup () {

    remove_action('wp_head', 'wlwmanifest_link'); // remove wlwmanifest.xml (needed to support windows live writer)
    remove_action('wp_head', 'wp_generator'); // remove wordpress version

    remove_action('wp_head', 'rsd_link'); // remove really simple discovery link
    remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0 ); // remove shortlink

    remove_action( 'wp_head', 'print_emoji_detection_script', 7 );  // remove emojis
    remove_action( 'wp_print_styles', 'print_emoji_styles' );   // remove emojis

    remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); // remove the / and previous post links

    remove_action('wp_head', 'feed_links', 2); // remove rss feed links
    remove_action('wp_head', 'feed_links_extra', 3); // removes all extra rss feed links

    remove_action( 'wp_head', 'rest_output_link_wp_head', 10 ); // remove the REST API link
    remove_action( 'wp_head', 'wp_oembed_add_discovery_links' ); // remove oEmbed discovery links
    remove_action( 'template_redirect', 'rest_output_link_header', 11, 0 ); // remove the REST API link from HTTP Headers

    remove_action( 'wp_head', 'wp_oembed_add_host_js' ); // remove oEmbed-specific javascript from front-end / back-end

    remove_action('rest_api_init', 'wp_oembed_register_route'); // remove the oEmbed REST API route
    remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10); // don't filter oEmbed results
add_action('after_setup_theme', 'wdv_cleanup');


Please be aware that if you intend in launching your theme to the public, you should not be removing things like Windows Live Writer support for example.

The reason is simple: you never know how someone is going to use your theme and they may need that or other things. And they will contact you requesting support for missing features.