WordPress auto generates a whole lot of unnecessary tags/elements that can not only slow down your website but also in some cases cause security issues. For instance, the WP Generator header tag gives away the current version of your WordPress site which is definitely not something that you want to reveal. So let's see what these elements are and how to remove them.
List of Unnecessary Elements in WordPress Header
Here is a list of auto-generated header tags that we will be removing (Of-course it goes without saying that not all these functions need to be removed. Remove whatever you feel is unnecessary and keep the rest.):
<link rel="profile" href="http://gmpg.org/xfn/11"> <link rel="pingback" href="#"> <link rel="alternate" type="application/rss+xml" title="Comments Feed" href="#" /> <link rel="EditURI" type="application/rsd+xml" title="RSD" href="xmlrpc.php?rsd" /> <link rel="wlwmanifest" type="application/wlwmanifest+xml" href="wlwmanifest.xml" /> <link rel='prev' title='#' href='#' /> <link rel='next' title='#' href='#' /> <meta name="generator" content="WordPress 4.1.1" /> <link rel='shortlink' href='#' /> <link rel='index' title='#' /> <link rel='start' title='#' />
Luckily removing these elements is very easy. All you need to do is open you theme's functions.php file and add a few lines of code to it.
1.) Removing XMLRPC, WLW, Generator, Feeds and ShortLink
To remove these tags, just add the following to your theme's functions.php page:
remove_action('wp_head', 'rsd_link'); //removes EditURI/RSD (Really Simple Discovery) link. remove_action('wp_head', 'wlwmanifest_link'); //removes wlwmanifest (Windows Live Writer) link. remove_action('wp_head', 'wp_generator'); //removes meta name generator. remove_action('wp_head', 'wp_shortlink_wp_head'); //removes shortlink. remove_action( 'wp_head', 'feed_links', 2 ); //removes feed links. remove_action('wp_head', 'feed_links_extra', 3 ); //removes comments feed.
2.) Removing Previous and Next Article Links
Previous and next article links can be removed by adding the following code to functions.php file:
/*Removes prev and next links*/ remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
Here's what Google says, "You can use the HTML attributes rel="next" and rel="prev" to indicate the relationship between individual URLs. Using these attributes is a strong hint to Google that you want us to treat these pages as a logical sequence." Read more here.
But oddly enough, wordpress adds these tags to all 'single post pages' (where these tags are not required) and fails to add the tags to 'paginated pages (archive pages, category pages, paginated homepage etc.)' where these tags are actually required!
This is why we can safely remove these tags using the above code. You can also add these tags to paginated pages (archive pages, category pages, paginated homepage etc.) by following this tutorial: https://orbitingweb.com/blog/add-next-prev-tags-to-wordpress-archive-pages/
3.) Removing XFN (XHTML Friends Network) Profile Link and Pingback URL
The rel=profile link and rel=Pingback tags can be removed directly by editing the header.php file. To do this, open your template's header.php file and remove the following lines:
<link rel="profile" href="http://gmpg.org/xfn/11"> <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
Creating a Plugin to Perform the Above Actions
Editing your theme's Header.php or Functions.php is an easy way to achieve certain functionalities, but the downside to this is that you would need to make all these changes over and over again if you were to change your theme or if the theme gets updated and you were not using a child theme. So to make these functions theme independent, it is optimal to use a plugin. Plugins once activated will keep working irrespective or the theme you use.
So here's how you can create a plugin to carry out the above actions:
Step 1: Open your favorite text editor. I recommend Notepad++.
Step 2: Add the following code to a blank file and save it as 'your-plugin-name.php' after making necessary edits:
<?php /* Plugin Name: Your plugin name goes here. Plugin URI: Your website/blog address goes here. Description: Removes unnecessary clutter from WPHead. Version: 1.0.0 Author: Your name goes here. Author URI: Your website/blog address goes here. */ /*Removes RSD, XMLRPC, WLW, WP Generator, ShortLink and Comment Feed links*/ remove_action('wp_head', 'rsd_link'); remove_action('wp_head', 'wlwmanifest_link'); remove_action('wp_head', 'wp_generator'); remove_action('wp_head', 'wp_shortlink_wp_head'); remove_action( 'wp_head', 'feed_links', 2 ); remove_action('wp_head', 'feed_links_extra', 3 ); /*Removes prev and next article links*/ remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
Step 3: Upload this file to your wordpress installments plugin directory.
Step 4: Activate the plugin from your dashboard by going to Plugins > Installed Plugins.
So this is how you can create a plugin to carry out similar actions.
Please Note: As mentioned before, not all these elements need to be removed as some of them are pretty useful when it comes to blog management. For instance, if you use the windows live writer to blog then you might not want to remove the wlwmanifest link.
And yes, the plugin has the option to remove all these unwanted tags.
You can also download the plugin from your wordpress dashboard by searching for 'Quick and easy seo tool by Mukesh Mani'. Your feedback is appreciated.
Here's an article I wrote detailing the plugin: https://orbitingweb.com/blog/quick-and-easy-seo-tool/