Skip to content

Instantly share code, notes, and snippets.

@dknauss
Created December 22, 2025 06:50
Show Gist options
  • Select an option

  • Save dknauss/2fa39047937d34643a7e4394ef26ad12 to your computer and use it in GitHub Desktop.

Select an option

Save dknauss/2fa39047937d34643a7e4394ef26ad12 to your computer and use it in GitHub Desktop.
Terence Eden's WordPress Debloat
<?php
if ( ! defined( "ABSPATH" ) ) {
die( "Invalid request." );
}
/* WordPress Tweaks */
// Remove mandatory classic theme.
function disable_classic_theme_styles():void {
wp_deregister_style( "classic-theme-styles" );
wp_dequeue_style( "classic-theme-styles" );
}
add_action( "wp_enqueue_scripts", "disable_classic_theme_styles" );
// Remove WP Emoji.
// http://www.denisbouquet.com/remove-wordpress-emoji-code/
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" );
// https://wordpress.org/support/topic/remove-the-new-dns-prefetch-code/
add_filter( "emoji_svg_url", "__return_false" );
// Stop emoji replacement with images in RSS / Atom Feeds
// https://danq.me/2023/09/04/wordpress-stop-emoji-images/
remove_filter( "the_content_feed", "wp_staticize_emoji" );
remove_filter( "comment_text_rss", "wp_staticize_emoji" );
// Remove automatic formatting.
// https://css-tricks.com/snippets/wordpress/disable-automatic-formatting/
remove_filter( "the_content", "wptexturize" );
remove_filter( "the_excerpt", "wptexturize" );
remove_filter( "comment_text", "wptexturize" );
remove_filter( "the_title", "wptexturize" );
// More formatting crap.
add_action("init", function() {
remove_filter( "the_content", "convert_smilies", 20 );
foreach ( array( "the_content", "the_title", "wp_title", "document_title" ) as $filter ) {
remove_filter( $filter, "capital_P_dangit", 11 );
}
remove_filter( "comment_text", "capital_P_dangit", 31 ); // No idea why this is separate
remove_filter( "the_content", "do_blocks", 9 );
}, 11);
// Remove Gutenberg Styles.
// https://wordpress.org/support/topic/how-to-disable-inline-styling-style-idglobal-styles-inline-css/
remove_action( "wp_enqueue_scripts", "wp_enqueue_global_styles" );
// Remove Gutenberg editing widgets.
// From https://wordpress.org/plugins/classic-widgets/
// Disables the block editor from managing widgets in the Gutenberg plugin.
add_filter( "gutenberg_use_widgets_block_editor", "__return_false" );
// Disables the block editor from managing widgets.
add_filter( "use_widgets_block_editor", "__return_false" );
// No widgets in this theme.
remove_theme_support( "widgets-block-editor" );
remove_theme_support( "widgets" );
// Remove Gutenberg Block Library CSS from loading on the frontend.
// https://smartwp.com/remove-gutenberg-css/
function remove_wp_block_library_css():void {
wp_dequeue_style( "wp-block-library" );
wp_dequeue_style( "wp-block-library-theme" );
wp_dequeue_style( "wp-components" );
}
add_action( "wp_enqueue_scripts", "remove_wp_block_library_css", 100 );
// Remove hovercards on comment links in admin area.
// https://wordpress.org/support/topic/how-to-disable-mshots-service/#post-12946617
add_filter( "akismet_enable_mshots", "__return_false" );
// Remove Unused Plugin code.
function remove_plugin_css_js():void {
wp_dequeue_style( "image-sizes" );
}
add_action( "wp_enqueue_scripts", "remove_plugin_css_js", 100 );
// Remove WordPress forced image size
// https://core.trac.wordpress.org/ticket/62413#comment:40
add_filter( "wp_img_tag_add_auto_sizes", "__return_false" );
// Remove <img> enhancements
// https://developer.wordpress.org/reference/functions/wp_filter_content_tags/
remove_filter( "the_content", "wp_filter_content_tags", 12 );
// Stop rewriting http:// URls for the main domain.
// https://developer.wordpress.org/reference/hooks/wp_should_replace_insecure_home_url/
remove_filter( "the_content", "wp_replace_insecure_home_url", 10 );
// Remove the attachment stuff
// https://developer.wordpress.org/news/2024/01/building-dynamic-block-based-attachment-templates-in-themes/
remove_filter( "the_content", "prepend_attachment" );
// Remove the block filter
remove_filter( "the_content", "apply_block_hooks_to_content_from_post_object", 8 );
// Remove browser check from Admin dashboard.
// https://core.trac.wordpress.org/attachment/ticket/27626/disable-wp-check-browser-version.0.2.php
if ( !empty( $_SERVER["HTTP_USER_AGENT"] ) ) {
add_filter( "pre_site_transient_browser_" . md5( $_SERVER["HTTP_USER_AGENT"] ), "__return_null" );
}
// Remove shortlink.
// https://stackoverflow.com/questions/42444063/disable-wordpress-short-links
remove_action( "wp_head", "wp_shortlink_wp_head" );
// Remove RSD.
// https://wpengineer.com/1438/wordpress-header/
remove_action( "wp_head", "rsd_link" );
// Remove extra feed links.
// https://developer.wordpress.org/reference/functions/feed_links/
add_filter( "feed_links_show_comments_feed", "__return_false" );
add_filter( "feed_links_show_posts_feed", "__return_false" );
// Remove api.w.org link.
// https://wordpress.stackexchange.com/questions/211467/remove-json-api-links-in-header-html
// remove_action( "wp_head", "rest_output_link_wp_head" );
// https://wordpress.stackexchange.com/questions/211817/how-to-remove-rest-api-link-in-http-headers
// https://developer.wordpress.org/reference/functions/rest_output_link_header/
remove_action( "template_redirect", "rest_output_link_header" );
/* Plugin Tweaks */
// ActivityPub
// Remove ActivityPub Plugin CSS
function remove_activitypub_block_css():void {
wp_dequeue_style( "activitypub-followers-style" );
wp_dequeue_style( "activitypub-follow-me-style" );
wp_dequeue_style( "activitypub-reactions-style" );
wp_dequeue_style( "activitypub-reply-style" );
}
add_action( "wp_enqueue_scripts", "remove_activitypub_block_css", 100 );
// Remove Fediverse Previews
// https://github.com/Automattic/wordpress-activitypub/blob/79ce3414b12b6dc80151de22ce10dce8d2cad9ab/includes/class-admin.php#L876
/**
* @param array<string> $actions
* @phpstan-ignore missingType.iterableValue
*/
function modify_list_row_actions( array $actions, WP_Post $post ):array {
return array_diff_key( $actions, array( "activitypub" => true ) );
}
add_filter( "post_row_actions", "modify_list_row_actions", 99, 2 );
// Remove ActivityPub vestigial script
// https://github.com/Automattic/wordpress-activitypub/issues/1340
function remove_activitypub_options_injection():void {
remove_action( "wp_head", array( "Activitypub\Blocks", "inject_activitypub_options" ), 11 );
}
add_action( "init", "remove_activitypub_options_injection", 15 );
add_filter( "activitypub_site_supports_blocks", "__return_false" );
// https://github.com/Automattic/wordpress-activitypub/issues/705#issuecomment-2045586378
add_action( "init", function() {
if ( !class_exists( "\Activitypub\Comment" ) ) {
return;
}
remove_action( "wp_enqueue_scripts", array( \Activitypub\Comment::class, "enqueue_scripts" ) );
remove_filter( "comment_reply_link", array( \Activitypub\Comment::class, "comment_reply_link" ) );
}, 999 );
// Remove Webmention custom comments
remove_action( "init", array( "\Webmention\Comment_Walker", "init" ) );
/* Obsolete */
// Remove Unused IndieWeb Widget code
// function remove_indieweb_widget_css(){
// wp_dequeue_style( "indieweb" );
// wp_dequeue_style( "webmention" );
// }
// add_action( "wp_enqueue_scripts", "remove_indieweb_widget_css", 100 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment