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
WordPress Themes
WordPress Top Theme List
WordPress Theme Files and Functions
WordPress Template Hierarchy
WordPress Enqueue Scripts and Styles
WordPress Loop
WordPress WP_Query Class
Exercises & Assignments
Build and activate a minimal classic theme
Show the three latest posts with WP_Query
Load a stylesheet with wp_enqueue_style and a version
Show a message only on the front page
Create a child theme which changes the footer
Interview Questions & Answers
What is a WordPress theme?
What are commonly used WordPress theme functions?
Which function is used to get the home URL in WordPress?
Which are the necessary files for a WordPress theme?
What is the use of the wp_head() function in WordPress?
What is the WordPress Loop?
What is the difference between is_home() and is_front_page()?