How To Clean Up Unnecessary Code From WordPress Header

There are a lot of code WordPress adds to header by default. This article will show you how to clean up and optimize your WordPress header.

How To Remove Weblog Client Link

Example:
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://www.example.com/xmlrpc.php?rsd" />

If you not are not using blog client to edit your WordPress site, then you do not need this link. To remove the EditURI/RSD link from WordPress header, paste the below code into your theme’s function.php.

remove_action ('wp_head', 'rsd_link');

How To Remove Windows Live Writer Manifest Link

Example:
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://www.example.com/wp-includes/wlwmanifest.xml" />

If you are not using Windows Live Writer, then remove this link. To remove the wlwmanifest link from WordPress header paste the below code into your theme’s function.php.

remove_action( 'wp_head', 'wlwmanifest_link');

How To Remove WordPress Generator (Version)

Example:
<meta name="generator" content="WordPress 4.6.1" />

I strongly recommend everyone to remove this piece of information form the header for security purpose.

To remove WordPress Generator from WordPress header paste the below code into your theme’s function.php.

remove_action('wp_head', 'wp_generator');

How To Remove Page/Post Shortlinks

Example:
<link rel='shortlink' href="http://www.example.com/?p=175">

This is the URL shortening feature provided by WordPress, but if you do no use this url, it is best to remove it from the header.

To remove page/post shortlinks from WordPress header paste the below code into your theme’s function.php.

remove_action( 'wp_head', 'wp_shortlink_wp_head');

How To Disable REST API Link – api.w.org

Example:
<link rel='https://api.w.org/' href='http://www.example.com/wp-json/' />

WordPress introduced many new REST API functionalities from version 4.4. If you do not use any of them, then it is recommended to disabled this feature.

To remove REST API Link – api.w.org from WordPress header paste the below code into your theme’s function.php.

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

How To Disable oEmbed Discovery Links and wp-embed.min.js

Example:
<link rel="alternate" type="application/json+oembed" href="https://example.com/wp-json/oembed/1.0/embed?url=https%3A%2F%2Fexample.com%2Fpath%2F"/>
<link rel="alternate" type="text/xml+oembed" href="https://example.com/wp-json/oembed/1.0/embed?url=https%3A%2F%2Fexample.com%2Fpath%2F&#038;format=xml"/>
<script type='text/javascript' src='https://example.com/wp-includes/js/wp-embed.min.js?ver=4.4.2'></script>

oEmbed discovery links are added from WordPress 4.4. oEmbed is a format for allowing an embedded representation of a URL on third party sites. The simple API allows a website to display embedded content (such as photos or videos) when a user posts a link to that resource, without having to parse the resource directly.

To remove oEmbed discovery links and wp-embed.min.js from WordPress header paste the below code into your theme’s function.php.

remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );
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);

How to Remove RSS Feed Links

Example:
<link rel="alternate" type="application/rss+xml" title="WDV &raquo; Feed" href="https://example.com/feed/" />
<link rel="alternate" type="application/rss+xml" title="WDV &raquo; Comments Feed" href="https://example.com/comments/feed/" />

To remove RSS feed links and wp-embed.min.js from WordPress header paste the below code into your theme’s function.php.

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

Conclusion

I like to clean up as much code as I can from WordPress. By removing and disabling the above functions, you are optimizing and securing your WordPress website.