Skip to content

Instantly share code, notes, and snippets.

@robinstickel
Created December 12, 2019 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robinstickel/73a545c2173adf7f3a64259b0cc9928d to your computer and use it in GitHub Desktop.
Save robinstickel/73a545c2173adf7f3a64259b0cc9928d to your computer and use it in GitHub Desktop.
Remove unnecessary Junk from Wordpress Header
<?php
// Remove WP emoji nonsense
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
// Remove all RSS feed links from wp_head
remove_action( 'wp_head','feed_links', 2 );
remove_action( 'wp_head','feed_links_extra', 3 );
// Resource Hints is a rather new W3C specification that “defines the dns-prefetch,
// preconnect, prefetch, and prerender relationships of the HTML Link Element (<link>)”.
// These can be used to assist the browser in the decision process of which origins it
// should connect to, and which resources it should fetch and preprocess to improve page performance.
remove_action( 'wp_head', 'wp_resource_hints', 2 );
// WordPress Page/Post Shortlinks
// URL shortening is sometimes useful, but this automatic ugly url
// in your header is useless. There is no reason to keep this. None.
remove_action( 'wp_head', 'wp_shortlink_wp_head');
// Weblog Client Link
// Are you editing your WordPress blog using your browser?
// Then you are not using a blog client and this link can probably be removed.
// This link is also used by a few 3rd party sites/programs that use the XML-RPC request formats.
// One example is the Flickr API. So if you start having trouble with a 3rd party service that
// updates your blog, add this back in. Otherwise, remove it.
remove_action ('wp_head', 'rsd_link');
// Windows Live Writer Manifest Link
// If you don’t know what Windows Live Writer is (it’s another blog editing client), then remove this link.
remove_action( 'wp_head', 'wlwmanifest_link');
// WordPress Generator (with version information)
// This announces that you are running WordPress and what version you are using. It serves no purpose.
remove_action('wp_head', 'wp_generator');
// Remove prev+next links from posts
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
// Sends a Link header for the REST API.
// https://developer.wordpress.org/reference/functions/rest_output_link_header/
remove_action( 'template_redirect', 'rest_output_link_header', 11, 0 );
// Outputs the REST API link tag into page header.
// https://developer.wordpress.org/reference/functions/rest_output_link_wp_head/
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
// https://developer.wordpress.org/reference/functions/wp_oembed_add_discovery_links/
remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );
// Remove REST API endpoint
remove_action('rest_api_init', 'wp_oembed_register_route');
// Remove oEmbed auto discovery
add_filter('embed_oembed_discover', '__return_false');
// Don't filter oEmbed results
remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10);
// Remove oEmbed-JavaScript
remove_action('wp_head', 'wp_oembed_add_host_js');
// Remove rewrite embed rules
add_filter('rewrite_rules_array', 'disable_embeds_rewrites');
@robinstickel
Copy link
Author

The code I use for new Wordpress themes to clean up the WP header. Heavily inspired by clean-wordpress-head from Pablo Vasconcelos.

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