Remove These 10 Unnecessary Tags from WordPress Header (WP Version, Prev, Pingback, Feed Links & More)

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');
Important Note 1: The 'Prev' and 'Next' tags are important for 'paginated pages (archive pages, category pages, tag pages, paginated homepage etc.)' as they help Google Bot identify if the page in question is part of a paginated sequence. Hence these tags can help prevent content duplication issues.

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/

Important Note 2: This won't be applicable to everyone, but if you are splitting your single posts using the <!--nextpage--> tag, then you can add the rel='next' and rel='prev' tags using this tutorial: https://orbitingweb.com/blog/adding-next-and-prev-tags-to-paginated-posts/

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.

References:
Removing extra lines from wp-head
WordPress Function Reference - Remove Action

 
 
 
 

Comments

  1. Alex says:

    Thanks! This was very useful.

  2. Mukesh says:

    No problem Alex, glad it was useful.

  3. Abbass says:

    hi, this was very useful for me, thanks a lot.

  4. Sagar Patil says:

    Can you make post about all this tags and what are use of this, so we can understand which one to remove and which not. Please.

    • M Mukesh says:

      Hi Sagar, Sure, will update this post with the information you asked for.

  5. Robz says:

    There is no reason to remove rel="next" and rel="prev" if you have paginated content on your website. See: support.google.com/webmasters/answer/1663744?hl=en

Leave a Reply

Your email address will not be published. Required fields are marked *