WordPress comes jam packed with things in the <head>
tag that I almost never want. For example:
- xmlrpc.php
- wlwmanifest.xml
- application/json+oembed
- wp-json
- Gutenberg block editor things such as classic-themes.min.css, wp-block-library-css, global-styles-inline-css, and a ton of svg elements after the opening <body> tag
- Default favicons (I add these back my own way)
- Emojis 😝
Removing these things can be done by adding the following to your functions.php file.
functions.php
// ***********************************
// Remove Bloat
// ***********************************
// Remove various bloat:
// <link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://domain.com/xmlrpc.php?rsd" />
// <link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://domain.com/wp-includes/wlwmanifest.xml" />
// <link rel="alternate" type="application/json+oembed" href="http://domain.com/wp-json/oembed/1.0/embed?url=http%3A%2F%2Fdomain.com%2F" />
// <link rel="https://api.w.org/" href="http://domain.com/wp-json/" />
// <link rel="alternate" type="application/json" href="http://domain.com/wp-json/wp/v2/pages/345" />
function remove_bloat() {
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_oembed_add_discovery_links');
// Disable the REST API endpoint
add_filter('rest_authentication_errors', '__return_true');
// Remove the REST API <link> elements
remove_action('wp_head', 'rest_output_link_wp_head');
}
add_action('init', 'remove_bloat', 30);
// Remove Gutenberg block editor:
// <link rel='stylesheet' id='classic-theme-styles-css' href='http://domain.com/wp-includes/css/classic-themes.min.css?ver=6.2.2' type='text/css' media='all' />
// <link rel='stylesheet' id='wp-block-library-css' href='http://domain.com/wp-includes/css/dist/block-library/style.min.css?ver=6.2.2' type='text/css' media='all' />
// <style id='global-styles-inline-css' type='text/css'> ... </style>
function remove_gutenberg() {
wp_dequeue_style('classic-theme-styles');
wp_dequeue_style('wp-block-library');
wp_dequeue_style('global-styles');
}
add_action('wp_enqueue_scripts', 'remove_gutenberg', 30);
// Remove default icons:
// <link rel="icon" href="http://domain.com/wp-content/uploads/2023/03/cropped-favicon-32x32.png" sizes="32x32" />
// <link rel="icon" href="http://domain.com/wp-content/uploads/2023/03/cropped-favicon-192x192.png" sizes="192x192" />
// <link rel="apple-touch-icon" href="http://domain.com/wp-content/uploads/2023/03/cropped-favicon-180x180.png" />
// <meta name="msapplication-TileImage" content="http://domain.com/wp-content/uploads/2023/03/cropped-favicon-270x270.png" />
function default_favicons() {
add_filter('get_site_icon_url', '__return_false');
}
add_action('init', 'default_favicons', 30);
// Remove emojis:
function disable_emojis() {
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_filter('the_content_feed', 'wp_staticize_emoji');
// remove_filter('comment_text_rss', 'wp_staticize_emoji');
// remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
}
add_action('init', 'disable_emojis', 30);
// Remove svg elements after opening <body> tag:
function remove_svg() {
remove_action('wp_enqueue_scripts', 'wp_enqueue_global_styles');
remove_action('wp_body_open', 'wp_global_styles_render_svg_filters');
}
add_action('init', 'remove_svg', 30)
?>