How to remove unnecessary elements in the HTML document head

All we need is an easy explanation of the problem, so here it is.

Is there a plugin or something that can help me out with deleting unnecessary elements in my code?

I am in charge of fixing a WordPress site and have been asked to remove the following elements that are not necessary, for example, I don’t have any pagination in my pages but in my code there is still:

  • <link rel='prev' title='Barcelona' href='http://www.creativesquaresummercamp.com/barcelona/' />

  • <link rel='next' title='Frequently Asked Questions'
    href='http://www.creativesquaresummercamp.com/frequently-asked-questions/'
    />

Again with the RSS feed:

  • <link rel="alternate" type="application/rss+xml" title="Creative Square
    Summer Camp RSS2 Feed"
    href="http://www.creativesquaresummercamp.com/feed/" rel="nofollow noreferrer noopener" />

How can I clean up the code / delete unnecessary elements?

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

This are default settings fron WordPress.
This was set via wp-includes/default_filters.php or the feed inside your theme.

Check the theme, functions.php for
add_theme_support( 'automatic-feed-links' );
and remove it.

Add this via plugin or functions.php in your theme for remove the different defaults, hints and small description is on the source.

remove_action( 'wp_head', 'feed_links_extra', 3 ); // Display the links to the extra feeds such as category feeds
remove_action( 'wp_head', 'feed_links', 2 ); // Display the links to the general feeds: Post and Comment Feed
remove_action( 'wp_head', 'rsd_link' ); // Display the link to the Really Simple Discovery service endpoint, EditURI link
remove_action( 'wp_head', 'wlwmanifest_link' ); // Display the link to the Windows Live Writer manifest file.
remove_action( 'wp_head', 'index_rel_link'); // index link
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); // prev link
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); // start link
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 ); // Display relational links for the posts adjacent to the current post.
remove_action( 'wp_head', 'wp_generator' ); // Display the XHTML generator that is generated on the wp_head hook, WP version

Method 2

Remove the following line from the theme’s functions.php:

add_theme_support( 'automatic-feed-links' );

… and add this to the file:

remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head' );

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply