Optimizing WordPress: A Simple Class to Remove Unnecessary Functions

Your WordPress might be optimized for performance. You have caching running, optimized images and your scripts and styles. And now you wonder what might be next to optimize WordPress further. You are a perfectionist, so how else can performance be improved? There are a number of functions WordPress which you might not need and can easily be disabled. I wrote a PHP class which does throws a couple these optimizations together in one class.

This class removes a couple of WordPress functionalities which you might not need, as well as a number of JavaScripts. In this way, your WordPress installation is made more lean and the amount of HTTP requests is reduced. And this in turn can enhance the loading speed of your site. Because the way it is set-up as a PHP class, you can easily enable or disable certain optimizations through one array of configurations.

View the class on github

How do I use this class?

Grab the class from github. Place the mt-wp-optimize.php file, which contains the class, in your WordPress plugin, theme or child theme.  Include it for example in functions.php or better, load it from a seperate file.  Now, create a new instance of this class.

$optimize = new MT_WP_Optimize($optimizations = array() );

The class accepts an array with the following keys and boolean, which in turn execute the optimization method if set to true.

no_scripts_styles_version (boolean):

If true, removes the version numbers from scripts and styles. Defaults to true.

no_wp_version (boolean):

If true, removes the WP version from the front-end. Defaults to true.

no_feed (boolean):

If true, removes the references to the feed and the feed functionality. Defaults to false.

no_shortlinks (boolean):

If true, removes the the WordPress shortlinks from your head section. Defaults to true.

no_rsd_manifest (boolean):

Removes the Really Simple Discoverability (RSD) links and the Windows Live Writer link from your head section. The RSD links are a bunch of XML rules to make your WordPress site more easy to discover for third party servics. The Windows live writer link allows to publish remotely to WordPress using the Windows Live Writer. You actually won’t need these two if you publish inside WordPress itself. Defaults to true.

no_wp_emoji (boolean):

Emojis are ideograms in WordPress and convert the use of typed emoticons into images. However, this functionality also adds another JavaScript file. Defaults to true.

disable_xmlrpc (boolean): 

XMLRPC allows several Webblog clients to publish to your blog remotely. The use of XMLRPC has also been notorious because it has been exploited by hackers to gain access to WordPress sites, but this has been improved in the last years. Disabling XMLRPC however breaks some functionalities of plugins and applications,, so use with caution. Defaults to true.

block_external_http (boolean):

Blocks external requests from plugins outside the admin area, thereby reducing the amount of external requests. Defaults to false.

stop_heartbeat (boolean):

Removes the heartbeat script from WordPress, improving Dashboard performance. The caveat is that the auto save functionality for posts is disabled when you remove this script. Also, some plugins use the heartbeat functionality and might get broken if heartbeat is disabled. Defaults to false.

disable_comments (boolean):

Closes comments by default and removes the comments option from the Dashboard, making your WordPress install more clean. If you don’t use comments at your site, it is pretty useful to disable them. Defaults to false.

no_jquery (boolean):

If you are running a lightweight site, your theme might not even need the whole jQuery library which is included by default. Defaults to false.

no_embed (boolean):

Since WordPress 4.4, embeds are enhanced and this introduces a new javascript to be loaded in the front-end. If you are not relying on embeds, such as video and audio, heavily, it is better to remove this script. Defaults to false.

Change the default configurations

As you can see, these arguments have default values which are contained in the class itself. Thus, if you are content with these values you do not need to add any arguments when you instantiate the class. If you want to alter the default values, you just have to pass your own array of enabled optimizations into the class, as shown in the example below:


$optimizations = array(
    'no_scripts_styles_version' => true,
    'no_wp_version'             => true,
    'no_feed'                   => true,
    'no_shortlinks'             => true,
    'no_rsd_manifest'           => true,
    'no_wp_emoji'               => true,
    'disable_xmlrpc'            => true,
    'block_external_http'       => true,
    'stop_heartbeat'            => true,
    'no_jquery'                 => true,    
    'no_embed'                  => true,
    'disable_comments'          => true    
$optimize = new MT_WP_Optimize($optimizations); 

Your input is welcome

I would love to make this class better and add more optimizations. Now this class is based on the optimizations and scripts I have found scrambling around the internet and stack-overflow searching for more ways to optimize WordPress. Big chance there might a lot more to incorporate. Do you have input for additional optimizations? I’d love to hear them!