WordPress comes with a lot of features, but some of them you might not need. Disabling these features can speed up your WordPress site.

By simply creating a new Theme in WordPress and adding wp_head() to your website, you will see a lot of things in your website source code that already come with WordPress, and you might not need them.

Here is an example of the code we have on the left, and the output on the right:

WordPress website with bloat, code example

Once I had formatted the code inside the Visual Studio Code, there were 386 lines of code.

Speed and Page Test With WordPress Bloat

I am doing tests on a shared SiteGround hosting with a server located in the UK, to start this is the result and the weight of the page I am getting.

The website has no plugins, any caching activated or any gzip, and here is the result from Pingdom:

Testing WordPress wbesite with all the bloat
Page size: 24.5kb. Load time is 123ms. 5 requests.

Removing WordPress Bloat

To remove the WordPress bloat you can add and remove some actions in the function.php file of your theme or inside a custom plugin, which you will see below.

Removing Emojis

WordPress comes preloaded with inline emoji script and styles, you may want to remove them if you have no comments section on your website, or a chat plugin, or you don’t want the emojis at all.

The following code removes the emoji script and styles:

function disable_wp_emojicons() {
  // all actions related to emojis
  remove_action( 'admin_print_styles', 'print_emoji_styles' );
  remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
  remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
  remove_action( 'wp_print_styles', 'print_emoji_styles' );
  remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
  remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
  remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
  // filter to remove TinyMCE emojis, with testing on New WordPress install it did trough an error
  // add_filter( 'tiny_mce_plugins', 'disable_emojicons_tinymce' );
}
add_action( 'init', 'disable_wp_emojicons' );

Reference: Stack Exchange

Result without WordPress emojis:

Page size: 18.4kb. Load time is 101ms. 4 requests.

Removing Gutenberg Block Library

In case you are not using a WordPress Gutenberg editor, you still get a block library loaded to your website, which looks something like this:

<link rel='stylesheet' id='wp-block-library-css'  href='https://wpbloat.webdevartur.com/wp-includes/css/dist/block-library/style.min.css?ver=6.0.1' type='text/css' media='all' />

We can remove the WordPress block library with the following code:

function wda_remove_wp_block_library_css(){
    wp_dequeue_style( 'wp-block-library' );
    wp_dequeue_style( 'wp-block-library-theme' );
    wp_dequeue_style( 'wc-blocks-style' ); // Remove WooCommerce block CSS, if you have WooCommerce activated
} 
add_action( 'wp_enqueue_scripts', 'wda_remove_wp_block_library_css', 100 );

Result without WordPress Gutenberg Block Library:

Page size: 13.2kb. Load time is 106ms. 4 requests.

Removing Global Styles from WordPress

With every Theme creation you start you will have global styles from WordPress, with a code like this:

<style id='global-styles-inline-css' type='text/css'>
body{--wp--preset--color--black: #000000;--wp--preset--color--cyan-bluish-gray: #abb8c3;--wp--preset--color--white: #ffffff;--wp--preset--color--pale-pink: #f78da7;--wp--preset--color--vivid-red: #cf2e2e;--wp--preset--color--luminous-vivid-orange: #ff6900;--wp--preset--color--luminous-vivid-amber: #fcb900;--wp--preset--color--light-green-cyan: #7bdcb5;--wp--preset--color--vivid-green-cyan: #00d084;--wp--preset--color--pale-cyan-blue: #8ed1fc;--wp--preset--color--vivid-cyan-blue: #0693e3;--wp--preset--color--vivid-purple: #9b51e0;--wp--preset--gradient--vivid-cyan-blue-to-vivid-purple: linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%);--wp--preset--gradient--light-green-cyan-to-vivid-green-cyan: linear-gradient(135deg,rgb(122,220,180) 0%,rgb(0,208,130) 100%);--wp--preset--gradient--luminous-vivid-amber-to-luminous-vivid-orange: linear-gradient(135deg,rgba(252,185,0,1) 0%,rgba(255,105,0,1) 100%);--wp--preset--gradient--luminous-vivid-orange-to-vivid-red: linear-gradient(135deg,rgba(255,105,0,1) 0%,rgb(207,46,46) 100%);--wp--preset--gradient--very-light-gray-to-cyan-bluish-gray: linear-gradient(135deg,rgb(238,238,238) 0%,rgb(169,184,195) 100%);--wp--preset--gradient--cool-to-warm-spectrum: linear-gradient(135deg,rgb(74,234,220) 0%,rgb(151,120,209) 20%,rgb(207,42,186) 40%,rgb(238,44,130) 60%,rgb(251,105,98) 80%,rgb(254,248,76) 100%);--wp--preset--gradient--blush-light-purple: linear-gradient(135deg,rgb(255,206,236) 0%,rgb(152,150,240) 100%);--wp--preset--gradient--blush-bordeaux: linear-gradient(135deg,rgb(254,205,165) 0%,rgb(254,45,45) 50%,rgb(107,0,62) 100%);--wp--preset--gradient--luminous-dusk: linear-gradient(135deg,rgb(255,203,112) 0%,rgb(199,81,192) 50%,rgb(65,88,208) 100%);--wp--preset--gradient--pale-ocean: linear-gradient(135deg,rgb(255,245,203) 0%,rgb(182,227,212) 50%,rgb(51,167,181) 100%);--wp--preset--gradient--electric-grass: linear-gradient(135deg,rgb(202,248,128) 0%,rgb(113,206,126) 100%);--wp--preset--gradient--midnight: linear-gradient(135deg,rgb(2,3,129) 0%,rgb(40,116,252) 100%);--wp--preset--duotone--dark-grayscale: url('#wp-duotone-dark-grayscale');--wp--preset--duotone--grayscale: url('#wp-duotone-grayscale');--wp--preset--duotone--purple-yellow: url('#wp-duotone-purple-yellow');--wp--preset--duotone--blue-red: url('#wp-duotone-blue-red');--wp--preset--duotone--midnight: url('#wp-duotone-midnight');--wp--preset--duotone--magenta-yellow: url('#wp-duotone-magenta-yellow');--wp--preset--duotone--purple-green: url('#wp-duotone-purple-green');--wp--preset--duotone--blue-orange: url('#wp-duotone-blue-orange');--wp--preset--font-size--small: 13px;--wp--preset--font-size--medium: 20px;--wp--preset--font-size--large: 36px;--wp--preset--font-size--x-large: 42px;}.has-black-color{color: var(--wp--preset--color--black) !important;}.has-cyan-bluish-gray-color{color: var(--wp--preset--color--cyan-bluish-gray) !important;}.has-white-color{color: var(--wp--preset--color--white) !important;}.has-pale-pink-color{color: var(--wp--preset--color--pale-pink) !important;}.has-vivid-red-color{color: var(--wp--preset--color--vivid-red) !important;}.has-luminous-vivid-orange-color{color: var(--wp--preset--color--luminous-vivid-orange) !important;}.has-luminous-vivid-amber-color{color: var(--wp--preset--color--luminous-vivid-amber) !important;}.has-light-green-cyan-color{color: var(--wp--preset--color--light-green-cyan) !important;}.has-vivid-green-cyan-color{color: var(--wp--preset--color--vivid-green-cyan) !important;}.has-pale-cyan-blue-color{color: var(--wp--preset--color--pale-cyan-blue) !important;}.has-vivid-cyan-blue-color{color: var(--wp--preset--color--vivid-cyan-blue) !important;}.has-vivid-purple-color{color: var(--wp--preset--color--vivid-purple) !important;}.has-black-background-color{background-color: var(--wp--preset--color--black) !important;}.has-cyan-bluish-gray-background-color{background-color: var(--wp--preset--color--cyan-bluish-gray) !important;}.has-white-background-color{background-color: var(--wp--preset--color--white) !important;}.has-pale-pink-background-color{background-color: var(--wp--preset--color--pale-pink) !important;}.has-vivid-red-background-color{background-color: var(--wp--preset--color--vivid-red) !important;}.has-luminous-vivid-orange-background-color{background-color: var(--wp--preset--color--luminous-vivid-orange) !important;}.has-luminous-vivid-amber-background-color{background-color: var(--wp--preset--color--luminous-vivid-amber) !important;}.has-light-green-cyan-background-color{background-color: var(--wp--preset--color--light-green-cyan) !important;}.has-vivid-green-cyan-background-color{background-color: var(--wp--preset--color--vivid-green-cyan) !important;}.has-pale-cyan-blue-background-color{background-color: var(--wp--preset--color--pale-cyan-blue) !important;}.has-vivid-cyan-blue-background-color{background-color: var(--wp--preset--color--vivid-cyan-blue) !important;}.has-vivid-purple-background-color{background-color: var(--wp--preset--color--vivid-purple) !important;}.has-black-border-color{border-color: var(--wp--preset--color--black) !important;}.has-cyan-bluish-gray-border-color{border-color: var(--wp--preset--color--cyan-bluish-gray) !important;}.has-white-border-color{border-color: var(--wp--preset--color--white) !important;}.has-pale-pink-border-color{border-color: var(--wp--preset--color--pale-pink) !important;}.has-vivid-red-border-color{border-color: var(--wp--preset--color--vivid-red) !important;}.has-luminous-vivid-orange-border-color{border-color: var(--wp--preset--color--luminous-vivid-orange) !important;}.has-luminous-vivid-amber-border-color{border-color: var(--wp--preset--color--luminous-vivid-amber) !important;}.has-light-green-cyan-border-color{border-color: var(--wp--preset--color--light-green-cyan) !important;}.has-vivid-green-cyan-border-color{border-color: var(--wp--preset--color--vivid-green-cyan) !important;}.has-pale-cyan-blue-border-color{border-color: var(--wp--preset--color--pale-cyan-blue) !important;}.has-vivid-cyan-blue-border-color{border-color: var(--wp--preset--color--vivid-cyan-blue) !important;}.has-vivid-purple-border-color{border-color: var(--wp--preset--color--vivid-purple) !important;}.has-vivid-cyan-blue-to-vivid-purple-gradient-background{background: var(--wp--preset--gradient--vivid-cyan-blue-to-vivid-purple) !important;}.has-light-green-cyan-to-vivid-green-cyan-gradient-background{background: var(--wp--preset--gradient--light-green-cyan-to-vivid-green-cyan) !important;}.has-luminous-vivid-amber-to-luminous-vivid-orange-gradient-background{background: var(--wp--preset--gradient--luminous-vivid-amber-to-luminous-vivid-orange) !important;}.has-luminous-vivid-orange-to-vivid-red-gradient-background{background: var(--wp--preset--gradient--luminous-vivid-orange-to-vivid-red) !important;}.has-very-light-gray-to-cyan-bluish-gray-gradient-background{background: var(--wp--preset--gradient--very-light-gray-to-cyan-bluish-gray) !important;}.has-cool-to-warm-spectrum-gradient-background{background: var(--wp--preset--gradient--cool-to-warm-spectrum) !important;}.has-blush-light-purple-gradient-background{background: var(--wp--preset--gradient--blush-light-purple) !important;}.has-blush-bordeaux-gradient-background{background: var(--wp--preset--gradient--blush-bordeaux) !important;}.has-luminous-dusk-gradient-background{background: var(--wp--preset--gradient--luminous-dusk) !important;}.has-pale-ocean-gradient-background{background: var(--wp--preset--gradient--pale-ocean) !important;}.has-electric-grass-gradient-background{background: var(--wp--preset--gradient--electric-grass) !important;}.has-midnight-gradient-background{background: var(--wp--preset--gradient--midnight) !important;}.has-small-font-size{font-size: var(--wp--preset--font-size--small) !important;}.has-medium-font-size{font-size: var(--wp--preset--font-size--medium) !important;}.has-large-font-size{font-size: var(--wp--preset--font-size--large) !important;}.has-x-large-font-size{font-size: var(--wp--preset--font-size--x-large) !important;}
</style>

You can remove WordPress Global Styles with the following code:

function wda_deregister_styles() {
    wp_dequeue_style( 'global-styles' );
}
add_action( 'wp_enqueue_scripts', 'wda_deregister_styles', 100 );

Result without WordPress Global Styles:

Results without Globals Style in WordPress
Page size: 23.4kb. Load time is 124ms. 5 requests.

Removing the WP-JSON link from WordPress

WordPress websites come with REST API, with well-written documentation, and it’s something you may not want to remove if you are not too familiar with it.

It requires to work with Gutenburg and may be required for some of the themes and/or plugins.

There is also a disadvantage to it, as it can leak data from your site, for example, if someone posted a blog on your site, we can find their username in the JSON file.

WordPress currently includes a wp-JSON link on all webpages, here is an example we will be removing:

<link rel="https://api.w.org/" href="https://wpbloat.webdevartur.com/wp-json/" /><link rel="EditURI" type="application/rsd+xml" title="RSD" href="https://wpbloat.webdevartur.com/xmlrpc.php?rsd" />

You can disable REST API with a “Disable REST API” plugin, but for now, we will remove the link from the head with the following code:

function wda_remove_rest_api () {
    remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
    remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );
}
add_action( 'after_setup_theme', 'wda_remove_rest_api' );

Result without WordPress wp-JSON link:

Page size: 24.5kb. Load time is 110ms. 5 requests.

So it has had not much impact on the page size.

Removing EditURI and wlwmanifest XML links

You only need those if you plan on using the Windows Live Writer tool to write your blogs, currently the code in wp_head() is:

<link rel="EditURI" type="application/rsd+xml" title="RSD" href="https://wpbloat.webdevartur.com/xmlrpc.php?rsd" />
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="https://wpbloat.webdevartur.com/wp-includes/wlwmanifest.xml" />

We can remove the EditURI and wlwmanifest XML with the following code:

function wda_remove_xml() {
    remove_action('wp_head', 'rsd_link');
    remove_action('wp_head', 'wlwmanifest_link');
}

Result without WordPress EditURI and wlwmanifest XML links:

Page size: 24.5kb. Load time is 127ms. 5 requests.
Page size: 24.5kb. Load time is 127ms. 5 requests.

This has not much impact on the page either.

Removing dns-prefetch link

DNS prefetching actually speeds up the website and can increase its performance of the website, and therefore it’s recommended to stay there, but I will do a test to see what we get.

This is what we see in the head:

<link rel='dns-prefetch' href='//s.w.org' />

Remove the dns-prefetch link with the following code:

remove_action( 'wp_head', 'wp_resource_hints', 2 );

Result without WordPress without dns-prefetch link:

Page size: 24.5kb. Load time is 123ms. 5 requests.
Page size: 24.5kb. Load time is 123ms. 5 requests.

Again, not much change is happening here.

Removing WordPress version generator

Finally, we can remove the WordPress version, also a good idea to prevent common attacks against your website.

The HTML code inside the head looks like this:

<meta name="generator" content="WordPress 6.0.1" />

Remove the WordPress version generator with the following code:

I don’t think I need to show you the test, as the results will stay the same as above.

Speed and Page Test Without All WordPress Bloat

For the final test, I have all code removed from WordPress wp_head() as seen in the picture below, from 386 lines of code down to 11 lines of code!

Final code result inside the page source

And here is the final result without WordPress Bloat:

Page size: 5.8kb. Load time is 76ms. 3 requests.
Page size: 5.8kb. Load time is 76ms. 3 requests.

Optimising Server & Activating SG Optimizer Plugin

Got a bit interesting to see what would happen on a SiteGround shared server if I had the optimisation switched on.

Here is what I turned on:

  1. NGINX Direct Delivery
  2. Memcached
  3. Installed and Activated the SiteGround Optimizer plugin
    1. Dynamic Caching
    2. File-Based Caching
    3. Memcached
    4. Purge SG Cache

And here is the result tested from the UK on Pingdom:

Results with optimising server and using a plugin

The load time has increased, as I did 3 different tests, and got one extra 0.1 KB on the Page Size, which is nothing.

Conclusion

Very impressed with the results at the end, all the way down from page size 24.5 kb to 5.8kb, and with 2 fewer requests.

Of course, as you are going to be building your website the page size, load time and requests will grow, but this is handy if you are a minimalist.

Full Code

//removes emojis
function disable_wp_emojicons() {
    // all actions related to emojis
    remove_action( 'admin_print_styles', 'print_emoji_styles' );
    remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
    remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
    remove_action( 'wp_print_styles', 'print_emoji_styles' );
    remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
    remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
    remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
  
     // filter to remove TinyMCE emojis, with testing on New WordPress install it did trough an error
    add_filter( 'tiny_mce_plugins', 'disable_emojicons_tinymce' );
  }
add_action( 'init', 'disable_wp_emojicons' );
// removes block library
function wda_remove_wp_block_library_css(){
    wp_dequeue_style( 'wp-block-library' );
    wp_dequeue_style( 'wp-block-library-theme' );
    wp_dequeue_style( 'wc-blocks-style' ); // Remove WooCommerce block CSS, if you have WooCommerce activated
} 
add_action( 'wp_enqueue_scripts', 'wda_remove_wp_block_library_css', 100 );
// removes global styles
function wda_deregister_styles() {
    wp_dequeue_style( 'global-styles' );
}
add_action( 'wp_enqueue_scripts', 'wda_deregister_styles', 100 );
// removes wp-json link
function wda_remove_rest_api () {
    remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
    remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );
}
add_action( 'after_setup_theme', 'wda_remove_rest_api' );

// remove XML links
function wda_remove_xml() {
    remove_action('wp_head', 'rsd_link');
    remove_action('wp_head', 'wlwmanifest_link');
}
add_action('init', 'wda_remove_xml');
// removes DNS Prefetch
remove_action( 'wp_head', 'wp_resource_hints', 2 );
// removes WordPress version
remove_action('wp_head', 'wp_generator');