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.
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.
require_once('classes/mt-wp-optimize.php'); $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.
If true, removes the version numbers from scripts and styles. Defaults to true.
If true, removes the WP version from the front-end. Defaults to true.
If true, removes the references to the feed and the feed functionality. Defaults to false.
If true, removes the the WordPress shortlinks from your head section. Defaults to true.
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.
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.
Blocks external requests from plugins outside the admin area, thereby reducing the amount of external requests. Defaults to false.
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.
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.
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.
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:
require_once('classes/mt-wp-optimize.php'); $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!