If you look at the source code for your WordPress site you may have noticed a bunch of code in your <head> tag that is not a part of your WordPress theme such as re=”alternative”, rel=”pingpack” and the current version number of your WordPress installation.
These are actions that are added by WordPress and displayed in your wp_head hook – so stop browsing all your theme files trying to figure out how to remove them because you won’t find it there. You’ll need to create some remove_action functions to clean up your WordPress head tag…I’ll show you how to do this.
WordPress <head> 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 read up on the rel tags before you go removing them all.
<link rel="alternate" type="application/rss+xml" title="WPExplorer RSS Feed" href="http://www.wpexplorer.com/feed/" /> <link rel="alternate" type="application/atom+xml" title="WPExplorer Atom Feed" href="http://www.wpexplorer.com/feed/atom/" /> <link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://www.wpexplorer.com/xmlrpc.php?rsd" /> <link rel="pingback" href="http://www.wpexplorer.com/blog/xmlrpc.php" /> <link rel='index' title='WP Engineer' href='http://www.wpexplorer.com' /> <link rel='start' title='WPExplorer' href='http://www.wpexplorer.com/folioway-wordpress-theme.html' /> <link rel='prev' title='WPExplorer' href='http://www.wpexplorer.com/sportpress-wordpress-theme.html' />
How To Remove The WP_Head Actions
In wordpress you can use the function “remove_action” to remove any function that is attached to a specific action hook.
The function remove_action:
remove_action( $tag, $function_to_add, $priority, $accepted_args );
Here you can see how I’ve used the remove_action function to clean up my header. Simply paste the code into your functions.php file to test it out. It should be pretty intuitive to see which action removes what.
// Remove junk from head remove_action( 'wp_head', 'rsd_link' ); remove_action( 'wp_head', 'wp_generator' ); remove_action( 'wp_head', 'feed_links', 2 ); remove_action( 'wp_head', 'index_rel_link' ); remove_action( 'wp_head', 'wlwmanifest_link' ); remove_action( 'wp_head', 'feed_links_extra', 3 ); remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 ); remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 ); remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
This could would be added in your child theme’s functions.php file. 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 content, leave it up to the end user if they want to remove this code or not.
Using a plugin: Additionally you could instead use a plugin to clean up your head for example the free “CC Clean Head Tags” plugin can be activated on your site to remove unnecessary code from your WordPress site’s head tag.