WordPress performance checklist for the end of the year
The end of the year is a good moment to look at the speed of a site. Faster pages rank better, sell better and need less server. Most points of this checklist take less than an hour, and you can do them in any order; the biggest gains usually come from page caching and images.
Problem: The site has become slower over the year, and it is not clear where to start.
Solution: Measure first, then go through the list: page caching, images, scripts and styles, the database, and the server (PHP version, compression, browser caching). Measure again after each change.
1. Measure
Test a few typical pages (home, a post, a category, a product) with PageSpeed Insights or GTmetrix and write down the results. Note the time to first byte separately: if it is high, the problem is on the server, not in the browser.
2. Page caching
Without caching, WordPress builds every page in PHP with dozens of database queries. A caching plugin stores the finished HTML:
wp plugin install wp-super-cache --activate
Many hosts have their own page cache; then a plugin is not needed, and two caches on top of each other only cause confusion.
3. Images
Upload images in a reasonable size (no 5000-pixel photos for a 800-pixel column), compress them, and do not generate sizes the theme never uses:
<?php
// Do not create the 768px "medium_large" size if the theme does not use it
add_filter( 'intermediate_image_sizes_advanced', function ( $sizes ) {
unset( $sizes['medium_large'] );
return $sizes;
} );
// JPEG quality of generated sizes (default 82)
add_filter( 'jpeg_quality', function () {
return 80;
} );
4. Scripts and styles
Plugins often load their files on every page. Check which ones are not needed where, and remove them there:
<?php
add_action( 'wp_enqueue_scripts', 'ha_dequeue_unused_assets', 99 );
function ha_dequeue_unused_assets() {
if ( ! is_page( 'contact' ) ) {
wp_dequeue_script( 'contact-form-7' );
wp_dequeue_style( 'contact-form-7' );
}
}
Scripts that are not needed for the first render can be loaded with defer, see async or defer for script tags in WordPress.
5. The database
Over the years the database collects revisions, expired transients and spam comments. Limit revisions in wp-config.php:
define( 'WP_POST_REVISIONS', 5 );
and clean up with WP-CLI (make a backup first):
wp db export before-cleanup.sql wp transient delete --expired wp post delete $(wp post list --post_type=revision --format=ids) --force wp comment delete $(wp comment list --status=spam --format=ids)
Deleting through WordPress instead of a raw SQL DELETE also removes the meta data of the deleted rows.
6. The server
Use PHP 7.2 or 7.3 if the host still runs PHP 5.6: it is the biggest free speed-up there is, often twice as fast. Check that the server compresses HTML, CSS and JS (gzip) and sends long browser caching headers for static files, and consider a CDN for images if visitors come from far away.
NOTE: Change one thing at a time and test on a staging copy. An optimisation that improves one number can break something else, for example a dequeued script that a page needs after all.