Colour
Text size
← All writing

How To Improve Speed And Performance For A WordPress Site

· 7 min read

Originally published on Search Engine Journal

I love WordPress, but it isn’t perfect out-of-the-box at all. Themes and plugin choices are more important than ever, where some can hamper the site’s performance. You can do many things to improve any WordPress site and this post will cover just some of these optimisations that you can (hopefully) take action on immediately.

Choose a reputable web hosting company

Choosing a bad host can be harmful to a site’s performance. Whilst hosting on a shared server may seem the most cost-effective, it definitely comes with its issues of sharing that server with other (potentially) troublesome sites that can monopolise shared resources to the detriment of your own. Hosting doesn’t cost the earth. I would always advise that you choose a web host that not only has great hardware specifications (on a dedicated server if budgets allow), but also understand both WordPress as well as offering strong technical support. And look for hosts with server-level caching.

Whether your site resides on a managed WordPress hosting platform, a LiteSpeed server or scalable cloud hosting, it’s always worth doing your own research and comparing a few companies before deciding. Also consider how SEO-friendly that host is. WordPress also has a hosting page with a handful of recommended companies.

Server optimisations and CDNs

Once the site is hosted on the server, there are further optimisations you can apply at server-level. Newer protocols like HTTP/3 and QUIC reduce latency, especially on mobile devices. Cloudflare and LiteSpeed support this out of the box but it is still worth checking with your server settings as well.

There are also several CDNs available, but my recommendation has always been to use Cloudflare. Their free plan offers many optimisations, including image polishing, caching and compression (enable tiered caching to further optimise those requests). I also recommend their APO (automatic platform optimization) offering costing $5 per site, or free with any of their paid plans.

Within Cloudflare, I recommend to cache everything except wp-admin and dynamic content, serve stale content while revalidating cache in the background as well as using their WAF (Web Application Firewall) services that help block attacks and limit crawlers.

Security & Performance Tweaks

There are several optimisations to remove and limit resources that are enabled by default in WordPress core. Two good recommendations here would be to disable XML-RPC if it is not required as well as limit Rest API access if not in use:

Disable XML-RPC

add_filter('xmlrpc_enabled', '__return_false');

Limit REST API Access

add_filter('rest_authentication_errors', function( $result ) {
    if( !is_user_logged_in() ) {
        return new WP_Error('rest_forbidden', 'REST API restricted', ['status' => 403]);
    }
    return $result;
});

There are more resources that I’d recommend you remove or limit, all of which can be done within the advanced settings of Yoast SEO Premium.

Caching & Compression Techniques

In addition to server optimisations, you can implement further performance enhancements by adding caching and compression elements directly.

Using object caching such as Varnish or Redis can provide great results, as well as setting proper cache-control headers within .htaccess (Apache) or nginx.conf:

<FilesMatch "\.(css|js|jpg|png|gif|woff2|ttf|svg|ico)$">
    Header set Cache-Control "max-age=31536000, public"
</FilesMatch>

Optimise Asset Loading

Now some caching and compression is in place, you can then take further steps to defer JavaScript, for example:

<script src="script.js" defer></script>

Also, try to have any scripts load asynchronously so that they don’t degrade initial page load times.

When it comes to CSS, it’s always good to remove any unused styles where possible although I wouldn’t say this is the biggest priority compared to other recommendations in this post. Also try to preload and preconnect fonts and other external resources where possible. Here is an example of how this can be done:

<link rel="preload" as="font" href="fonts/myfont.woff2" type="font/woff2" crossorigin="anonymous">

Closing other holes

If you’re a perfectionist like me, there’s always room for more optimisations!

  • Enable lazy loading for images where possible and replace YouTube embeds with static image previews.
  • Use Screaming Frog to detect unnecessary redirects.
  • Close redirect loops and chains, which are reported within Semrush site audits. Update internal links to point directly to the final destination URL.
  • Reduce third-party requests where possible. For example, load Google Analytics or Google Fonts locally instead of via external scripts.
  • Disable unused social media widgets and embeds

Theme & plugin considerations

OK, so you have your hosting account set up and your WordPress site installed. However, the abundance of choice you have when it comes to themes and plugins makes it hard to make informed decisions and choose trusted developers. This is a challenge that has always been present, and I have been writing about it since 2013 at least.

When choosing both themes and plugins, consider the following when doing so:

  • Is the theme compatible with the most recent versions of WordPress?
  • Does it adhere to WordPress best practices for theme and plugin development. You can check this using the Theme Check plugin for themes, and the Plugin Check for plugins.
  • Does the author of the theme have developer E-E-A-T? Can you trust them?
  • Ensure there isn’t too much code bloat. The more a theme is generalised to the masses (eg “all-in-one themes for any business”) the more will have to be developed to accommodate the widest of audiences. The more bespoke the theme, (presumably) the less of a chance of code bloat.
  • Read reviews and investigate support offerings. For themes and plugins offered within WordPress’s own repo, there are reviews and ratings that are always helpful to inform your decisions.

Most themes offer live previews, so it’s worth running those URLs through speed testing tools such as PageSpeed Insights, Web Page Test and Chrome DevTools.

Some WordPress-specific optimisations

Still not done with my perfectionism! Here are some recommendations on WordPress. The WP Heartbeat API can create unnecessary AJAX requests. Reduce its frequency or disable it:

add_action( 'init', function() {
    wp_deregister_script('heartbeat');
});

You can also limit post revisions and revision time intervals in wp-config.php:

define('WP_POST_REVISIONS', 5);
define('AUTOSAVE_INTERVAL', 300); // 5 minutes

Disabling unused Gutenberg block CSS is also recommended if not needed:

add_filter('use_block_editor_for_post', '__return_false');

There are so many plugins available today that it seems daunting to know which ones are the best and most trusted. Of course, “it depends” comes into play again, but generally, I advise that you use as few plugins as possible. If you can solve some issues away from a plugin (e.g., server-level), then do that first. Depending on what optimisations you may have set up elsewhere, some of these plugins may be unnecessary to install, but if not, it’s always good to know preferable options.

  • Caching and compression: Autoptimize, W3 Total Cache or Jetpack alongside WP Super Cache and Jetpack Boost.
  • Preloading: instant.page is a great recommendation here. Uses one line of code that you can implement or they offer a WordPress plugin that does the same.
  • Script deferring: some plugins above offer this, but I personally use WP Meteor.
  • Image optimisation: TinyPNG or Smush for image compression, WebP express for serving WebP images over PNG/JPG/EPS. For further optimisation use Edge Images for utilising edge transformation services to <img> markup.
  • SEO: while not directly connected to improving speed, Yoast SEO optimises a site’s visibility performance [disclosure, I work for Yoast]. Most of these features provided in the free version help with this, but things such as IndexNow are included within Premium. However, if you want to enable IndexNow without Premium, then Bing offers its own plugin.

When installing any plugin, it’s always good to look at all settings properly and disable anything that is not required to save more processing time and reduce code bloat. To take this to the next level, you may also want to install Plugin Organizer where you can set conditions for plugins to load only within relevant pages/areas of the site.

Server Monitoring

Lastly, it’s always good to have a good monitoring system such as New Relic on the server. This system allows you to diagnose and fix any issues that may be hampering the site or server’s performance, as well as reduce further unnecessary server load by disabling non-essential PHP modules.

You can also set up logging for slow queries in MySQL:

SET GLOBAL slow_query_log = 'ON';
SET GLOBAL long_query_time = 1;

I also recommend the Query Monitor plugin. Or, installing Blackfire to pick up inefficient code snippets which cause slow server response time. It is a paid tool, but highly recommended for enterprise level.

Error logs are always your friend, too in order to diagnose other issues. WordPress also offers debug mode, which is extremely useful for diagnosing potential problems by adding the following in wp-config.php:

Note, this should never be enabled on a live production site as it may expose sensitive information. Use on staging only.

// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );

// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );

Conclusion

As you can see, there is a lot one can do to improve a WordPress site, and it’s important to do so from multiple angles. Do as much as you can above, ensuring the site functions as it should. Test everything first to ensure everything you need is correctly implemented and doesn’t hamper other things on the site (e.g., sometimes caching or compressing JS can create irregularities or stop some site elements from working) or create other conflicts. And then deploy!

Alex Moss

Connect with me...

Elsewhere on the web, I'm generally active on Linkedin and X. Feel free to connect - or if you'd like to chat about working together then please fill out the contact form.

Get in touch

Tell me what you're working on. I read everything and reply within a working day.