To clean up WordPress's head output, remove only the discovery tags and compatibility features your site does not use. Keep the canonical tag, required block styles, and asset versions. Removing a tag is different from disabling the feature behind it.
I use a small must-use plugin so these decisions survive a theme switch. The configurable example below covers emojis, shortlinks, feed discovery, oEmbed discovery, and generator tags. It leaves feed URLs and embedded content working unless I explicitly choose otherwise. The page also covers the two CSS decisions in the head: removing the wp-block-library CSS (only on sites with no blocks) and inlining small critical CSS.
Choose only the features your site does not use
| Feature | What removal changes | Check before removing |
|---|---|---|
| Emoji support | Detection, optional polyfill, styling and email/feed substitution | Emoji display on the browsers and operating systems you support |
| Shortlink discovery | HTML tag and HTTP Link header | Clients that consume shortlinks; ?p=123 still works |
| Feed discovery | RSS/Atom <link> tags | Subscribers and integrations; feed endpoints remain live |
| oEmbed discovery | Other sites' discovery of your post embeds | Whether other publishers embed your posts |
| Generator output | Version metadata | This does not secure an outdated installation |
The savings depend on what a page actually loads. A removed tag saves HTML bytes; a conditional script can also save a request when it would otherwise load. Measure the Network panel and page timing before claiming a speed improvement. Feeds and embeds are useful features, and their existence alone is not evidence of an SEO problem.
One configurable must-use plugin
Save this as wp-content/mu-plugins/te-head-cleanup.php. Create the directory if necessary. Change the booleans to match the site's requirements; the conservative default removes shortlink and generator discovery only.
<?php
/**
* Plugin Name: TE Head Cleanup
* Plugin URI: https://techearl.com/clean-up-wordpress-wp-head
* Description: Selective cleanup of WordPress discovery output.
* Version: 2.0.0
* Author: Ishan Karunaratne
* Author URI: https://techearl.com
* License: GPL-2.0-or-later
*/
defined( 'ABSPATH' ) || exit;
add_action( 'init', function () {
$features = array(
'emojis' => false,
'shortlinks' => true,
'feed_links' => false,
'oembed_discovery' => false,
'generator' => true,
'rsd' => false,
);
if ( $features['emojis'] ) {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_enqueue_scripts', 'wp_enqueue_emoji_styles' );
remove_action( 'admin_enqueue_scripts', 'wp_enqueue_emoji_styles' );
// Compatibility with installations using the pre-6.4 callbacks.
remove_action( 'wp_print_styles', 'print_emoji_styles' );
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_filter( 'emoji_svg_url', '__return_false' );
add_filter( 'tiny_mce_plugins', function ( $plugins ) {
return is_array( $plugins )
? array_values( array_diff( $plugins, array( 'wpemoji' ) ) )
: $plugins;
} );
}
if ( $features['shortlinks'] ) {
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10 );
remove_action( 'template_redirect', 'wp_shortlink_header', 11 );
}
if ( $features['feed_links'] ) {
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'feed_links_extra', 3 );
}
if ( $features['oembed_discovery'] ) {
add_filter( 'oembed_discovery_links', '__return_empty_string' );
}
if ( $features['generator'] ) {
remove_action( 'wp_head', 'wp_generator' );
add_filter( 'the_generator', '__return_empty_string' );
}
if ( $features['rsd'] ) {
remove_action( 'wp_head', 'rsd_link' );
}
}, 100 );The priority passed to remove_action() must match the original registration. For example, emoji detection uses priority 7, feed links use 2 and 3, and the shortlink header uses 11. Register the removal after core has registered the callback and before the callback runs.
Emoji scripts and styles
WordPress tests emoji support and may load a compatibility script when needed. Removing it does not remove Unicode characters from your posts, but it gives rendering responsibility to the visitor's browser and fonts. “Modern browser” does not guarantee support for every newer emoji sequence.
The plugin removes both the current enqueue callbacks and the older style-printing callbacks. print_emoji_styles() was deprecated in WordPress 6.4. The TinyMCE filter applies to the classic editor; it is not a block-editor setting. The feed and email filters control conversion to image-based emoji in those outputs, so include them only if that is the intended behavior.
Shortlink tag and Link header
These are separate outputs:
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10 );
remove_action( 'template_redirect', 'wp_shortlink_header', 11 );Removing discovery does not disable https://example.com/?p=123. WordPress can still resolve that query to the post. Do not remove that access path merely to hide the tag.
curl -sS https://example.com/sample-post/ | grep -i shortlink
curl -sSI https://example.com/sample-post/ | grep -i shortlink
curl -sSI 'https://example.com/?p=123'Expect no shortlink output from the first two when those options are enabled; inspect the third separately for the site's normal redirect or response.
Feed tags, comments feeds and feed URL behavior
Removing feed_links and feed_links_extra removes discovery, not /feed/, /comments/feed/, or ?feed=rss2. To keep the main feeds advertised but remove contextual links, remove only feed_links_extra at priority 3. To suppress the global comments-feed tag while keeping the posts-feed tag:
add_filter( 'feed_links_show_comments_feed', '__return_false' );That filter also changes discovery only. Existing subscribers can still request the feed.
If the site has deliberately retired all feeds and has no equivalent replacement, a separate optional handler can return 410 Gone. Keep the rewrite rules so WordPress recognizes both pretty and query-string feed requests:
add_action( 'template_redirect', function () {
if ( ! is_feed() ) {
return;
}
nocache_headers();
wp_die( 'This feed has been retired.', 'Feed unavailable', array( 'response' => 410 ) );
}, 1 );For a moved feed, use a permanent redirect to the exact replacement feed instead. A homepage is not a replacement for every feed. Do not remove feed rewrite rules and then expect is_feed() to identify the now-unmatched URLs. Do not derive a redirect by merely stripping /feed/; query-string feeds need explicit handling and can otherwise redirect to themselves.
oEmbed provider cleanup without breaking pasted embeds
WordPress can both provide embeds of its posts and consume embeds from elsewhere. Hiding its provider discovery links is straightforward:
add_filter( 'oembed_discovery_links', '__return_empty_string' );This filter has existed since WordPress 4.4. It avoids relying on a particular head-hook priority.
For an intentional provider shutdown, the following optional code removes only the provider REST route and redirects recognized post-embed documents to their actual published post. It keeps the consumer proxy and host script available:
add_filter( 'rest_endpoints', function ( $routes ) {
unset( $routes['/oembed/1.0/embed'] );
return $routes;
} );
add_action( 'template_redirect', function () {
if ( ! is_embed() ) {
return;
}
$post = get_queried_object();
if ( $post instanceof WP_Post && is_post_publicly_viewable( $post ) ) {
wp_safe_redirect( get_permalink( $post ), 301 );
exit;
}
}, 1 );Removing a route from rest_endpoints makes it unavailable; it does not merely hide it from the API index. This is intentional for the provider route above.
Leave embed_oembed_discover unchanged if pasted embeds from arbitrary providers must continue working. Leave wp_oembed_add_host_js registered: WordPress uses its presence when deciding whether to enqueue wp-embed for consumed WordPress post embeds. Removing all wp_oembed_register_route registration would also remove the consumer proxy route.
Existing consumed embeds have per-post caches. Provider discovery cleanup does not require deleting those caches. If you change consumer behavior, use a scoped cache-maintenance procedure for affected posts and verify the available commands with wp help embed; never use wp post meta delete --all as an embed-cache shortcut, because that option concerns all metadata for a specified object.
Generator tags and asset versions
remove_action( 'wp_head', 'wp_generator' ) removes the HTML generator. The the_generator filter also suppresses generator strings in other supported output formats, including feeds. Neither patches a vulnerability or reliably hides a WordPress version. Keep core, plugins and themes updated.
Leave asset ?ver= parameters alone. They help invalidate browser/CDN caches when an asset changes. For a stylesheet you own, supply its real version when enqueueing it:
add_action( 'wp_enqueue_scripts', function () {
$file = get_stylesheet_directory() . '/assets/site.css';
if ( is_file( $file ) ) {
wp_enqueue_style(
'te-site',
get_stylesheet_directory_uri() . '/assets/site.css',
array(),
(string) filemtime( $file )
);
}
} );Do not replace versions on arbitrary plugin assets or use the current time as the version on every request.
Remove wp-block-library CSS
Beyond tags, the head carries the core block stylesheets. To dequeue them, hook wp_enqueue_scripts at a late priority and drop the handles. Most sites should not do this: the block editor has been the default since WordPress 5.0, so a typical front end renders block markup (columns, buttons, galleries, cover blocks) that depends on exactly this CSS. Strip it there and the layout breaks.
The handles you will see in the page source:
wp-block-library: the core block styles, the rules that lay outcore/columns,core/buttons,core/gallery,core/coverand the rest. On a current install its minifiedstyle.min.cssis roughly 25 to 30 KB, and it is a real render-blocking request.wp-block-library-theme: a smaller set of theme-facing block styles (the default look of a pull quote or separator).classic-theme-styles: a compatibility stylesheet added in WordPress 6.1 viawp_enqueue_classic_theme_styles(), enqueued for classic themes so Button and File blocks keep their back-compat styling.global-styles: added in 5.9 withtheme.json; inline<style>output of your color, spacing and typography presets rather than a file request.
When removing block CSS is safe
Only two kinds of site qualify: a classic-editor site whose content is plain TinyMCE HTML with no block markup, or a page-builder-only site (Elementor, Beaver Builder, Bricks, Divi or similar) where the builder ships its own CSS and core blocks never appear in the output. To check, open a post in the editor (a block list means block markup) or search the front-end source for wp-block- classes such as wp-block-columns or wp-block-button. If they appear, keep the CSS.
On a qualifying site, keep the change in a must-use plugin so it survives a theme switch, wp-content/mu-plugins/te-remove-block-css.php:
<?php
/**
* Plugin Name: TE Remove Block Library CSS
* Plugin URI: https://techearl.com/clean-up-wordpress-wp-head
* Description: Dequeues the core block stylesheets on the front end. Only for sites that render no block markup.
* Version: 1.0.0
* Author: Ishan Karunaratne
* Author URI: https://techearl.com
* License: GPL-2.0-or-later
* Text Domain: te-remove-block-css
*/
add_action( 'wp_enqueue_scripts', function () {
wp_dequeue_style( 'wp-block-library' );
wp_dequeue_style( 'wp-block-library-theme' );
wp_dequeue_style( 'classic-theme-styles' );
wp_dequeue_style( 'global-styles' );
}, 100 );Priority 100 matters: core enqueues these at the default 10, so a dequeue at 10 may run before there is anything to remove. These are removed with wp_dequeue_style() rather than remove_action() because core enqueues them during the normal asset pass. The exception is global-styles: because an action callback generates it inline, the dequeue does not always clear it. If the inline global CSS is still in the source, remove the callback instead:
add_action( 'wp_enqueue_scripts', function () {
remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' );
remove_action( 'wp_footer', 'wp_enqueue_global_styles', 1 );
}, 1 );Load block CSS per block instead
If the site does use blocks, the middle path is to split the monolithic stylesheet into per-block stylesheets and print only the blocks actually present on the page. Core has supported this since WordPress 5.8:
add_filter( 'should_load_separate_core_block_assets', '__return_true' );A post with a paragraph and an image then stops carrying the CSS for galleries, columns and cover blocks, and nothing breaks because every block still gets its styles. It is a global toggle, so test multi-column layouts, buttons and galleries afterwards. Block themes already behave closer to this model, so the win is largest on classic themes that opt in.
Check the layout after removing block CSS
curl -s https://example.com/ | grep -i block-library returning nothing only proves the stylesheet is gone. The real test is visual: logged out, click through every template (home, a post, a page, an archive, a custom front page) and an old post too, looking at multi-column layouts, buttons, galleries, cover overlays, separators and pull quotes. One legacy post built with a block is enough to break that page. If anything looks wrong, put the CSS back; there is no middle ground worth one request. If the stylesheet survives the snippet, purge the page cache, confirm the priority, and look for a plugin re-enqueueing block CSS after your callback.
Inline CSS in WordPress
The opposite move to removing a stylesheet is inlining a small one: printing the CSS directly in the <head> so a few KB of critical CSS arrives with the HTML instead of as a separate render-blocking request. There are two ways, and they solve different problems.
| Approach | Needs an enqueued handle? | Where it hooks | Best for |
|---|---|---|---|
wp_add_inline_style() | Yes (no-ops without one) | wp_enqueue_scripts | Dynamic CSS tied to a loaded stylesheet (Customizer color, per-page override) |
wp_head <style> echo | No | wp_head | Standalone critical CSS with no parent stylesheet |
If you only want to add a few rules without code, Appearance, Customize, Additional CSS saves CSS to the database and prints it in the head for you. The code routes below are for dynamic CSS and for critical CSS shipped from your own plugin.
wp_add_inline_style on an enqueued handle
wp_add_inline_style() appends your CSS in a <style> block right after the handle's <link> tag:
add_action( 'wp_enqueue_scripts', function () {
wp_enqueue_style( 'te-theme', get_stylesheet_uri() );
$accent = sanitize_hex_color( get_theme_mod( 'accent_color', '#0b5fff' ) );
$css = ":root { --accent: {$accent}; } a { color: var(--accent); }";
wp_add_inline_style( 'te-theme', $css );
} );The catch that trips everyone: it only outputs if the handle is actually enqueued on that page, not merely registered, and there is no error when it no-ops. Call it on wp_enqueue_scripts, not wp_head. Any value from user input or the database must be sanitized before it lands in a <style> block; a Customizer color goes through sanitize_hex_color().
Echo critical CSS on wp_head
When the CSS has no parent stylesheet, print it yourself. This must-use plugin (wp-content/mu-plugins/te-inline-css.php) reads a readable assets/critical.css next to it, collapses whitespace, and prints it early in the head:
<?php
/**
* Plugin Name: TE Inline CSS
* Plugin URI: https://techearl.com/clean-up-wordpress-wp-head
* Description: Inlines a small critical CSS file on wp_head instead of enqueuing a separate render-blocking stylesheet.
* Version: 1.0.0
* Author: Ishan Karunaratne
* Author URI: https://techearl.com
* License: GPL-2.0-or-later
* Text Domain: te-inline-css
*/
function te_inline_css() {
$file = __DIR__ . '/assets/critical.css';
if ( ! is_readable( $file ) ) {
return;
}
// Collapse runs of whitespace to a single space; trim the ends.
$css = preg_replace( '#\s+#', ' ', trim( file_get_contents( $file ) ) );
echo '<style id="te-critical-css">' . $css . '</style>' . "\n";
}
add_action( 'wp_head', 'te_inline_css', 8 );Priority 8 prints it before the theme's enqueued styles. The minify is deliberately crude; real critical CSS comes from an extractor that works out which rules apply above the fold (the critical and criticalcss npm packages, Penthouse, or criticalcss.com), and WP Rocket, Jetpack Boost, Autoptimize and LiteSpeed Cache can generate and inline it for you. On a high-traffic site, cache the minified string in a transient instead of running the regex on every request.
When inlining helps and when it hurts
Inlined CSS is not cached separately by the browser: an enqueued stylesheet is fetched once, while inlined CSS is re-sent in the HTML on every page load. So inline only small, above-the-fold CSS, and keep full theme stylesheets and frameworks enqueued. On HTTP/2 and HTTP/3, many small requests multiplex cheaply, so inlining to cut request count buys little; what still wins is removing the render-blocking round trip for critical CSS. A full-page cache or CDN HTML cache also serves the old inlined styles until purged, so purge before debugging the PHP.
To verify, check the block is in the head and the file is not also fetched:
$ curl -s https://example.com/ | grep -o '<style id="te-critical-css">'
<style id="te-critical-css">
$ curl -s https://example.com/ | grep -i 'critical.css'
(no output)For a wp_add_inline_style() block, view the source and confirm the <style> sits right after its parent <link rel="stylesheet">; if it is missing, the parent handle was not enqueued on that page.
Flush rewrite rules once and test removed and retained behavior
The examples here keep rewrite rules in place, so they need no rewrite flush. If you adapt the code to add or remove rules, rebuild the stored rule map once after deployment with wp rewrite flush or Settings → Permalinks. Repeat once after removing that rule-changing code. Do not flush on every request; must-use plugins have no activation hook.
After purging page caches, check a logged-out post, the homepage, a post containing a video and a WordPress-post embed, the editor, and any feed consumers. Match expectations to the enabled switches:
curl -sS https://example.com/sample-post/ | grep -iE 'emoji|shortlink|oembed|generator|application/rss'
curl -sSI https://example.com/sample-post/
curl -sSI https://example.com/feed/
curl -sSI 'https://example.com/?feed=rss2'
curl -sSI https://example.com/sample-post/embed/An empty grep result is not a universal pass condition: retained features should still appear, and a word such as “emoji” can occur in ordinary article text. Inspect the actual tags, HTTP status and browser behavior. Keep canonical tags intact.
For larger performance work, continue with ACF profiling, WooCommerce optimization, or the separately tested Dashicons and jQuery Migrate decisions, and the block CSS decision above.
If your front end renders any block markup, yes: columns stack wrong, buttons lose their styling, galleries collapse. It is only safe on a classic-editor site or one where every page is built in a page builder that ships its own CSS, and even then verify visually. Block-based sites should use should_load_separate_core_block_assets instead.
It is the inline CSS WordPress 5.9 and later generate from the theme's theme.json. On a no-block site you can remove it along with the block CSS (via remove_action on wp_enqueue_global_styles if the dequeue leaves it behind). On a block-based or block-theme site, leave it.
Almost always because the handle you passed is not enqueued on that page. wp_add_inline_style() only outputs when its parent handle is enqueued, not merely registered, and it fails silently. Call it on wp_enqueue_scripts.
No. Inlining removes a render-blocking request, which helps for a few KB of critical CSS, but inlined CSS is re-sent in the HTML on every page load instead of being cached once. For a large stylesheet that makes the site slower overall.
No. Removing feed_links and the shortlink callbacks removes discovery only. /feed/, ?feed=rss2 and ?p=123 keep working unless you add separate code to retire them.
Sources
Authoritative references this article was fact-checked against.
- WordPress remove_actiondeveloper.wordpress.org
- Current emoji style callbackdeveloper.wordpress.org
- oEmbed discovery filterdeveloper.wordpress.org
- WordPress post-embed host scriptdeveloper.wordpress.org
- Consumer discovery filterdeveloper.wordpress.org
- WP-CLI metadata deletion semanticsdeveloper.wordpress.org
- WordPress feed detectiondeveloper.wordpress.org
- Rewrite flushingdeveloper.wordpress.org
- wp_dequeue_style(): WordPress Developer Referencedeveloper.wordpress.org
- wp_enqueue_scripts hook: WordPress Developer Referencedeveloper.wordpress.org
- Block Editor Handbook: theme support and block stylesheetsdeveloper.wordpress.org
- should_load_separate_core_block_assets filter: WordPress Developer Referencedeveloper.wordpress.org
- wp_add_inline_style(): WordPress Developer Referencedeveloper.wordpress.org
- wp_enqueue_style(): WordPress Developer Referencedeveloper.wordpress.org
- wp_head hook: WordPress Developer Referencedeveloper.wordpress.org





