Skip to content

Instantly share code, notes, and snippets.

@khoipro
Last active February 15, 2024 16:05
Show Gist options
  • Save khoipro/72761b70925fbee3d52f41a3d572fede to your computer and use it in GitHub Desktop.
Save khoipro/72761b70925fbee3d52f41a3d572fede to your computer and use it in GitHub Desktop.
Remove Unnecessary Code in WordPress Header
// Remove Meta Generator: <meta name="generator" content="WordPress x.x" />
// and <meta name="generator" content="WooCommerce x.x.x" />
remove_action('wp_head', 'wp_generator');
// Remove the EditURI/RSD
// Like: <link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://localhost/wp/xmlrpc.php?rsd" />
remove_action ('wp_head', 'rsd_link');
// Remove it if you don't know what is Windows Live Writer
// <link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://localhost/wp/wp-includes/wlwmanifest.xml" />
remove_action( 'wp_head', 'wlwmanifest_link');
// Remove page/post's short links
// Like: <link rel='shortlink' href='http://localhost/wp/?p=5' />
remove_action( 'wp_head', 'wp_shortlink_wp_head');
// Remove feed links
// Like: <link rel="alternate" type="application/rss+xml" title="WP Site &raquo; Feed" href="http://localhost/wp/feed/" />
remove_action( 'wp_head', 'feed_links', 2 );
// Remove comment feeds
// Like: <link rel="alternate" type="application/rss+xml" title="WP Site &raquo; Comments Feed" href="http://localhost/wp/comments/feed/" />
remove_action('wp_head', 'feed_links_extra', 3 );
// Remove PREV and NEXT links
// Like: <link rel='prev' title='The Post Before This One' href='http://localhost/wp/?p=4' />
remove_action('wp_head', 'adjacent_posts_rel_link');
@elliottmangham
Copy link

I also use:

// Disable REST API link tag
remove_action('wp_head', 'rest_output_link_wp_head', 10);

// Disable oEmbed Discovery Links
remove_action('wp_head', 'wp_oembed_add_discovery_links', 10);

// Disable REST API link in HTTP headers
remove_action('template_redirect', 'rest_output_link_header', 11, 0);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment