Clean Up the WordPress wp_head: Remove Generator, Emoji and Extra Links

WordPress prints some extra tags in the <head> of every page: the version number (generator), emoji scripts, an RSD link and a shortlink. Many sites do not need them. Removing them makes the HTML smaller, and hides the WordPress version from simple scanners.

add_action( 'init', function () {
	remove_action( 'wp_head', 'wp_generator' );                  // <meta name="generator">
	remove_action( 'wp_head', 'rsd_link' );                      // Really Simple Discovery
	remove_action( 'wp_head', 'wlwmanifest_link' );              // Windows Live Writer
	remove_action( 'wp_head', 'wp_shortlink_wp_head' );          // <link rel="shortlink">
	remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
	remove_action( 'wp_print_styles', 'print_emoji_styles' );
} );

Test it

Terminal output

$ curl -s http://example.com/ | grep -c -E 'name="generator"|rel="EditURI"|rel="shortlink"|wp-emoji|emoji'
9

Terminal output

$ curl -s http://example.com/ | grep -c -E 'name="generator"|rel="EditURI"|rel="shortlink"|wp-emoji|emoji'
0

The first count (before the snippet) is higher than zero, and after we added the code the extra lines are gone. The count can be different in your theme, because some themes remove or add these tags by themselves.

A note

  • Hiding the version is a very small help for security. Real security needs updates and strong passwords.
  • Removing the emoji scripts means emoji will use the emoji of the browser or system. This is fine for the modern browsers.
  • Do not remove wp_head() itself. Plugins and the theme need it.

Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.