Tutorials

WordPress Speed Optimization; A Practical and Actionable Guide

A practical guide to WordPress speed optimization; from cache and database to PHP version. With before-and-after measurement methods, common mistakes, and answers to frequently asked questions.

Tutorials

Why Your WordPress Site Is Slow and Where to Start

Your site scores 45 on PageSpeed and images load late. Or maybe you have a TTFB above 1.5 seconds and users close the page before seeing the content. You know this situation: you've installed many plugins, each claiming to optimize, but the result hasn't changed.

Before making any changes, you must measure the current state. Without an initial number, you can't gauge the impact of your work.

For measurement, use GTmetrix or PageSpeed Insights. You also have a command-line tool that is more accurate:

curl -o /dev/null -s -w "TTFB: %{time_starttransfer}s\nTotal: %{time_total}s\n" https://example.com

Run this command three times and take the average. A TTFB above 600 milliseconds means the problem is on the server side, not the theme or plugins.

Important note: If your site is on shared WordPress hosting, also check the results during peak hours (9 PM to midnight Iran time). Speed at 3 AM is almost always good.

First Step: A Cache Plugin and Setting It Up Correctly

Caching is the simplest and most effective task. But installing a plugin isn't enough. Most people install the plugin and leave the default settings. That's a mistake.

Among cache plugins, I recommend WP Rocket (commercial) and LiteSpeed Cache (free, only on LiteSpeed). If your hosting is Apache or Nginx, WP Super Cache or W3 Total Cache are free options.

Settings you should change:

  • Enable Page Cache and set the expiration time to 3600 seconds
  • Turn on Minify for HTML and CSS, but be cautious with JavaScript. Combining JS files can sometimes break scripts
  • Enable Lazy Load for images
  • Set Browser Cache with a max-age of at least 2678400 seconds (one month)

After enabling cache, measure TTFB again. If the number drops below 300 milliseconds, the main problem is solved.

Here's Where They Go Wrong: You Enable Cache but the Page Is Still Slow

Sign of this problem: TTFB has dropped but Total Time is still high. That means HTML arrives quickly but CSS and JS files load late. This means page cache is working, but you haven't enabled browser cache or CDN. Check the Browser Cache settings, and if your hosting has a CDN, turn it on.

Database: Where Most Sites Forget to Look

WordPress runs several queries against the database every time a page loads. If the database is bloated, these queries become slow. The problem is that most site administrators never look at the database.

First task: check the tables. Use phpMyAdmin or the command line:

mysql -u username -p database_name -e "SHOW TABLE STATUS;"

Look at the Data_free column. If you see a high number, it means the tables are fragmented. This happens after lots of deletions and edits.

To optimize tables, use the following command:

mysql -u username -p database_name -e "OPTIMIZE TABLE wp_options, wp_posts, wp_postmeta;"

Do this once a month. But be careful: if your site is large (more than 100,000 posts), optimization may take a few minutes and temporarily take the site offline. In that case, do it during low-traffic hours.

Second task: check the wp_options table. This table usually causes the biggest problem. Deleted plugins sometimes leave their data in this table. With this query, you can see what's there:

SELECT option_name, LENGTH(option_value) AS size FROM wp_options ORDER BY size DESC LIMIT 20;

If you see large rows from deleted plugins, remove them. But before deleting, take a database backup. Take this seriously.

A Real Trade-off: Database Cleanup vs. Risk

Database cleanup plugins like WP-Optimize make the job easy, but sometimes they delete rows they shouldn't. For example, they remove session data of logged-in users and force-log them out. I prefer to do cleanup manually, only on specific tables. If you don't have time, run the plugin with limited settings (only deleting revisions and data from deleted plugins).

PHP Version: The Easiest Win You're Ignoring

WordPress runs about 3 times faster on PHP 7.4 than on PHP 5.6. PHP 8.2 is also about 20-30% faster than 7.4. You can see this number with a simple benchmark.

If your site is still on PHP 7.4 or lower, change this first. But before changing, do the following:

  1. Take a full backup of the site and database
  2. Update all plugins and the theme to the latest versions
  3. Change PHP in a staging environment (if you have one) and test
  4. If you don't have a test environment, change PHP and immediately check the site

Common error after PHP upgrade: white screen or 500 error. This is usually due to an old plugin that isn't compatible with the new version. In this case, via FTP or the hosting file manager, temporarily rename the wp-content/plugins folder to something else to deactivate all plugins. The site comes back up and you can activate plugins one by one.

To check the current PHP version, go to "Tools" and "Site Health" in the WordPress dashboard. Or use the command line:

php -v

If your hosting supports PHP 8.2 or 8.3, migrate to it. On Linux hosting, this is usually done through the control panel in a few clicks.

Images: The Heaviest Part of Every Page

Images typically make up 60-70% of a page's weight. A 2 MB image uploaded in PNG format can ruin the entire page speed.

Simple rule: optimize images before uploading. Tools like Squoosh or ImageOptim reduce size without noticeable quality loss. Choose WebP format; in most cases, it's 30-50% lighter than JPEG.

For images already uploaded, plugins like ShortPixel or Imagify do the job. But there's a limitation here too: the free version of these plugins has a limited monthly quota (e.g., 100 images per month). If your site has thousands of images, you need to buy the paid version or optimize images manually.

In addition to optimization, check image dimensions too. If an image with a width of 4000 pixels is displayed in a 600-pixel column, the browser has to download the large file and then shrink it. That's wasteful.

Order of Tasks: What to Do First

If you have limited time, follow this order:

  1. Upgrade the PHP version to 8.2 or higher (if you haven't already)
  2. Install and configure a cache plugin
  3. Optimize the database
  4. Optimize the images on the first page (the ones users see first)

After each step, measure TTFB and Total Time. Write down the result. This shows you which step had the most impact.

For more accurate measurement and interpreting results, read the website speed test tools guide. If your site frequently goes offline and this affects speed, also check website uptime monitoring.

Frequently Asked Questions

What is the best cache plugin for WordPress?

WP Rocket is the best commercial option, and LiteSpeed Cache is the best free option, provided your hosting uses LiteSpeed. If your hosting is Nginx or Apache, WP Super Cache is a reliable choice. Don't leave any plugin without manual configuration; default settings are usually not enough.

Why is the TTFB of my WordPress site high?

High TTFB means the server takes too long to generate a response. Common reasons: old PHP version, bloated database, heavy plugin, or limited resources on shared hosting. First check the PHP version, then optimize the database, and finally deactivate unnecessary plugins.

Is WordPress database optimization safe?

If you use reputable tools and take a backup before anything, it's safe. But automatic cleanup plugins sometimes delete important data. The manual method with OPTIMIZE TABLE queries is safer. Only optimize tables that are actually fragmented.

How often should I optimize the WordPress database?

For typical sites, once a month is enough. If your site is high-traffic or produces lots of content, every two weeks. Over-optimization also hurts; if the database is small and healthy, touching it only creates unnecessary risk.

ServerNet Support

ServerNet engineering & editorial team — specialists in infrastructure, networking and web hosting.

WordPress Hosting
Share:

Comments 0

No comments yet — be the first!

Leave a comment

Related service

WordPress Hosting

A purpose-built WordPress stack on LiteSpeed Enterprise and NVMe — auto-install, secure updates, staging and caching that keeps you on top of Google.