Blog WordPress fixes

How to speed up a slow WordPress site

Slow WordPress sites usually share the same handful of causes. Here they are, in the order that gives the biggest gain, with the plugins and code that fix each one.

Illustration for the post "How to speed up a slow WordPress site"

Start with a measurement

Test your key pages in PageSpeed Insights on the mobile setting and note the largest content paint and the time to first byte. A slow first byte points to hosting or caching. A slow content paint points to heavy images, scripts or styles.

To see which plugin or query is responsible, install Query Monitor on a test copy. It lists slow database queries and shows what each plugin adds to every page.

Fix 1: hosting and PHP

Cheap shared hosting is a common cause. Look for a host with current PHP, server-level caching and enough resources for your traffic, and switch your site to a recent, supported PHP version, which is often noticeably faster than an old one.

Fix 2: caching

Without caching, WordPress builds each page from the database on every visit. Use one page caching solution, either from your host or a single well-regarded plugin, and not several at once, which can conflict. Add an object cache if your site is busy or runs a store.

Fix 3: images

Resize photos before uploading, serve them in WebP or AVIF, and let images load lazily, apart from the one at the top of the page. WordPress sets sizes and lazy loading for you in current versions, so the main job is not uploading files that are much bigger than needed.

Tell the browser to fetch the main image first by preloading it. Add this to your theme’s functions.php, or a small code-snippets plugin, and change the address to your own hero image.

functions.php: preload the top-of-page image php
add_action( 'wp_head', function () {
  if ( is_front_page() ) {
    echo '<link rel="preload" as="image" href="https://example.com/hero.webp" fetchpriority="high">';
  }
}, 1 );

Fix 4: plugins and page builders

Every plugin can add scripts and styles, and some add them to every page. Remove the ones you do not use, replace heavy ones with lighter alternatives and load features only on the pages that need them. A heavy page builder, layered on a heavy theme, is a frequent reason a site cannot get faster. Fewer plugins also means a smaller security surface.

WordPress also loads emoji scripts on every page, which almost no site needs. This snippet removes them.

functions.php: remove the emoji scripts php
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' );

Fix 5: tidy the database and add a CDN

Clear old post revisions, expired transients and spam comments, and limit how many revisions WordPress keeps. A content delivery network then serves images and files from a location near each visitor, which helps most when your audience is spread across countries.

Take a backup first. Then either use a plugin, or these commands if you have WP-CLI.

wp-config.php: keep only the last five revisions php
define( 'WP_POST_REVISIONS', 5 );
Clean and optimise the database with WP-CLI bash
wp transient delete --expired
wp post delete $(wp post list --post_type=revision --format=ids) --force
wp db optimize

Measure again

Measure again after each change. If the score still disappoints, a custom lightweight theme is often the biggest remaining gain.

Common questions

Why is my WordPress site so slow?

The usual causes are slow hosting or an old PHP version, no page caching, oversized images, too many or heavy plugins and a bloated theme or page builder. Measure first to see which applies to you.

How many plugins are too many for WordPress?

There is no fixed number. What matters is what each plugin loads on every page. A few heavy plugins can slow a site more than dozens of light ones, so test with Query Monitor.

Which caching plugin is best for WordPress?

LiteSpeed Cache if your host runs LiteSpeed, WP Rocket if you want the easiest paid option, and WP Super Cache if you want a simple free one. Use only one page cache at a time.

What is a good load time for a WordPress site?

Aim for the main content to appear within about two and a half seconds on a mobile connection, which is Google’s threshold for a good largest contentful paint.