If you look at the source code for your WordPress site you may have noticed a bunch of code (junk) in your
<head> tag that is not a part of your WordPress theme such as the the current version number of your WordPress installation,
This is code added by WordPress by default and injected via the
wp_head hook. WordPress actually inserts quite a bit of code into your site header, a lot of which is not even needed for your site and may in fact be beneficial to remove.
In order to clean up your WordPress header you will need to create some
remove_action functions and I will show you how below!
What is WordPress Header Junk?
Below are some examples of what is added to your header. In my opinion a lot of these are unnecessary and I actually remove them all from my site’s header, which is why I call them “junk”. But it really depends on your site and your needs, so you want to Google search what each of these do before removing them all.
<link rel="alternate" type="application/rss+xml" title="Site Name RSS Feed" href="your-site.com/feed/" /> <link rel="alternate" type="application/atom+xml" title="Site Name Atom Feed" href="your-site.com/feed/atom/" /> <link rel="EditURI" type="application/rsd+xml" title="RSD" href="your-site.com/xmlrpc.php?rsd" /> <link rel="pingback" href="your-site.com/blog/xmlrpc.php" />
How to Clean up Your Header?
WordPress inserts the code into your site head tag via a function name
add_action which is used to run functions at specific points (hooks). So to remove the code you will need to use the opposite
remove_action( $hook_name, $callback, $priority );
Looking at the example above you can see that the remove_action function takes 3 parameters. The hook name, callback and priority. The hook name is the location where the code is being inserted (in this case it will be wp_head), the callback is the original function used to insert the code and the priority is the exact priority used when adding the original action callback.
// Remove rsd link. remove_action( 'wp_head', 'rsd_link' ); // Remove the WordPress generator tag. remove_action( 'wp_head', 'wp_generator' ); // Remove RSS feed links. remove_action( 'wp_head', 'feed_links', 2 ); remove_action( 'wp_head', 'feed_links_extra', 3 ); // Remove the link to the Windows Live Writer manifest file. remove_action( 'wp_head', 'wlwmanifest_link' ); // Removes the adjacent post links. remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 ); remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 ); // Removes the WordPress shortlink for your post. remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 ); // Remove emoji detection scripts. remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
Simply paste the code into your child theme functions.php file or via a code snippets plugin to test it out. I’ve commented everything above, but it should also be intuitive to see which action removes what based on the callback function name.
Important: I would never recommend adding this code to a theme for sale or distribution because you are taking away from the end user without their consent. Leave it up to the end user if they want to clean up their site header or not.
Clean Up Your Header using a Plugin
If you rather use a plugin instead of custom code there are a few good ones out there and I would probably recommend using the “WP Head Cleaner” plugin which can be activated on your site to remove unnecessary code from your WordPress site’s head tag.
The WP Head Cleaner plugin includes an options panel so you can choose what does and doesn’t get removed. I downloaded the plugin and took a look at the code and the plugin is coded well, but because the plugin is developed and maintained by a 3rd party developer don’t come after me if you there is an issue!
There isn’t a single WordPress site I run where I don’t add some code to clean up the header to remove WP junk. In my opinion WordPress shouldn’t be forcing things onto the user either and there should be built in settings so you can check what you do and don’t want added to your site header.
Let me know in the comments below if you have any thoughts, feedback or suggestions!