Improving WordPress by editing wp_options and Autoloaded data

WordPress Articles by BizWeb Consulting

Firstly, when we need to thank the folks over at Kinsta for putting together the amazing article titled ‘How to Clean up Your wp_options Table and Autoloaded Data‘ that has helped me over the years with speeding some of my own websites. 

When we use WordPress websites, we install plugins and then delete them if we don’t like them, they no longer are supported, another company buys them out and they become something you no longer need, and in many circumstances, information is left behind in the database. Another example could be when you’ve installed a theme, installed the demo content, and deleted plugins like wooCommerce and its left data behind.

Earlier today, I looked at one of my own websites – https://www.forgone.org and found that pieces of information were in the Autoloads of the database leftover from the previous theme that I had installed and did a clean trying to improve the performance of a light and basic WordPress website.

What is wp_options

The wp_options table is the table that WordPress stores the majority of information pertaining to the operation of the site. Thus, the name wp_options and it stores information such as the site’s URL, the site’s name and description, what theme is being used, image sizes and all sorts of information.

The fields in this table, as can be seen in the image below are simply option_id, option_name, option_value & autoload.

Where there is a yes in the autoload option, it instructs WordPress to load that information on every page of the WordPress site.

When a site has been running for so long, different plugins installed, the database grows in size and the more information could be flagged to autoload, even though the information is not even required any more.

What’s more is that these autoloaded options are loaded on every single page load and  can really slow down the speed of the website.

How big is autoloaded data?

The first thing we want to do is check the size of the data that is being autoloaded, to do this we need to log into phpMyAdmin and use the SQL string below.

It’s also a good thing to know that if your database is using different prefixes, such as ex_ instead of wp_ then you’ll need to adjust the syntax.

You will then get a value like the one below and anything above 1MB needs to be cleaned up. This site is 1.96MB and needs to be addressed.

SELECT SUM(LENGTH(option_value)) AS autoload_size 
FROM wp_options 
WHERE autoload = 'yes';

Kinsta has provided the following code that can be used to display the autoloaded data size, how many entries are in the table, and the first 10 entries by size.

SELECT 'autoloaded data in KiB' as name, 
       ROUND(SUM(LENGTH(option_value)) / 1024) as value 
FROM wp_options 
WHERE autoload = 'yes'
UNION
SELECT 'autoloaded data count', 
       count(*) 
FROM wp_options 
WHERE autoload = 'yes'
UNION
(SELECT option_name, 
        length(option_value) 
FROM wp_options 
WHERE autoload = 'yes' 
ORDER BY length(option_value) DESC 
LIMIT 10)

Sort Autoloaded Data

We can list the top items with autoloaded data by size. The two examples below provide the Top 10 and the Top 200.

Limit list to Top 10

SELECT option_name, length(option_value) AS option_value_length 
FROM wp_options 
WHERE autoload='yes' 
ORDER BY option_value_length DESC 
LIMIT 10;

Limit list to 200

SELECT option_name, length(option_value) AS option_value_length 
FROM wp_options 
WHERE autoload = 'yes' 
ORDER BY option_value_length DESC 
LIMIT 200;

In the image below, I went ahead and did the 200 items list and noticed that there were a few things of interest, for example there are entries for ‘rank-math’. 

Rank Math is an SEO plugin that I’ve been using on sites and recently removed it as I’m currently experimenting with a different SEO plugin. Thus, those entries do not need to there.

Find Specific Data

In order to find information related to specific plugins that we are no longer using. Cleaning up remnants from leftover plugins and themes using this command will come in handy. 

As mention above, there are quite a few for RankMath and there’s no reason for RankMath entries to load, therefore I can proceed with removing the autoloaded entries.

SELECT *
FROM wp_options
WHERE autoload = 'yes'
AND option_name LIKE '%rank-math%'

After taking a database backup, I can select the boxes above and remove those autoload entries as they’re no longer required.

WordPress Sessions

Another example that has been provided is WordPress sessions that could end up with lots and lots of rows. 

We recently migrated 598 posts over from one WordPress website to another and found that it was gutted with these records, we were unable to migrate the posts as the import process would crashed because of bloated records.

SELECT *
FROM wp_options
WHERE option_name LIKE '_wp_session_%'

Transient Cache

In one of the images above, there is the autoloaded option of _transient_dirsize_cache and I’ve wondered what it was, there were copious files being called upon. A thorough google search resulted in many results and the results have highlighted that this is used primarily for multisite installations and used to determine whether sites have exceeded their storage allocation. By removing the transient, WordPress would regenerate and to remove caching would not work either.

Although, we can edit the record to ‘autoload=no’ as per Liew CheonFong’s recommendation below which we’ve implemented ourselves.

Error Messages

You may encounter an error in the MySQL that reads:

#1054 – Unknown column ‘’yes’’ in ‘WHERE’

The issue is with the type of quotes used around ‘yes’ in the SQL query. MySQL expects standard single quotes, but when copying & pasting, it uses a different type of quote that MySQL doesn’t recognise.

In Summary

To summarise, if you’re not confident in the works of working with databases and SQL then avoid doing this yourself.

You can always set an autoload option to ‘no’ to test out if it makes an impact on the site rather than deleting it.

ALWAYS, ALWAYS, ALWAYS BACKUP!

If you’d like to leave us feedback, reach out to us at BizWeb Consulting

Scroll to Top