How to Clean up Autoloaded Options in WordPress

One of the most common cause of slow WordPress sites, especially with initial loading times, is a too large autoloaded options size. Autoloaded options are automatically loaded with every page load in WordPress.

Autoloaded options are set by plugins, themes and WordPress core. They define how WordPress sites are supposed to function and include options like the default URL, what theme is used, admin user and more.

Autoloaded options are great, but they can also be misused. Some plugins don’t actually need all their options to be autoloaded, and some plugins don’t clean up their autoloaded options when they’re deactivated or deleted from WordPress.

If you have an older WordPress site, there is a good chance that the autoloaded options are much bigger than they need to be. This is also common with site where many different plugins and themes have been used or only simply tested in the past.

The autoloaded options for a WordPress site should not be more than 900 kb (less than 1 MB).

How to check the autoloaded options size in WordPress

The easiest way to check the size of the autoloaded options is with the WP-CLI doctor command. This WP-CLI command is included with all our plans here at Servebolt. Here is the full command:

wp doctor check autoload-options-size

This command will output something like this:

| name | status | message |
| autoload-options-size | success | Autoloaded options size (607.69kb) is less than threshold (900kb). |

Or even worse, something like this:

| name | status | message |
| autoload-options-size | warning | Autoloaded options size (45.32mb) exceeds threshold (900kb) |

We have a more in-depth article on the WP-CLI doctor command here: How to diagnose your WP site using WP Profile and WP Doctor

The 900 kb limit is not a exact limit to a fast or slow WordPress site, but one should always try to reduce the autoloaded options size as much as possible. Again, this data is included with every single page load in WordPress.

How to clean up the autoloaded options

Before you do anything else, make sure to create a manual backup of your WordPress database. Here at Servebolt it’s only a matter of logging in to your server and running a single command, as described here: How to backup your WordPress site

Clean up autoloaded options using phpMyAdmin

Autoloaded options are set in the database table wp_options (or *_options, depending on your database prefix in WordPress). The easiest way to see what options are autoloaded is using phpMyAdmin. Login to the database, select the wp_options table and view the options with the column “autoload”.

Here is the SQL command for this:

SELECT * FROM wp_options WHERE autoload LIKE 'yes';

You can also list the autoloaded options in order of size using the following SQL command:

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

The option names are set by the individual plugins/themes, so it’s pretty easy to determine what options are necessary. Feel free to delete the autoloaded options that aren’t necessary, or change the autoload value for them to “no”.

What options to delete/change depends on your WordPress site setup. If you don’t recognize an option name, search the name using Google or similar, and it will usually indicate the name of the plugin creating the option.

We have also seen cases where a single plugin creates a very large number of autoloaded options, with similarly named options. If you find this in your database, be sure to notify the plugin developer about it.

Again, make sure to create a backup of your database before making any changes to this table. The wp_options table is a pretty critical table and you may break your site if you remove the wrong options.

Clean up autoloaded options using a WordPress plugin

There are multiple WordPress plugins available to clean the autoloaded options in WordPress. A plugin that we have used successfully in the past is Advanced DB Cleaner Pro. This is a paid plugin, that also includes functions for some other database optimizations.

Once the plugin has been purchased and installed, visit the WP DB Cleaner page in the WordPress admin panel. Select the “Options” tab and click the “Scan options” button.

A progress bar of the scan will be displayed. Note that the scan can take a while with larger option database tables. Once the scan is done, the section named “Orphans” will be populated.

Click the “Orphans” section link to display all options that WP DB Cleaner consider to be orphan options. Check the options that aren’t necessary for your WordPress site and delete or change the autoloaded switch using the form on this page.

WP DB Cleaner can also be used to clean up other parts of the WordPress database, but that’s outside the scope of this article. Feel free to use the plugin as you wish. If you deactivate/delete the plugin, it will clean up after itself.

Check the autoloaded options size again

Once you have cleaned up the autoloaded options in phpMyAdmin or using a WordPress plugin, be sure to check the size again. Here’s an example of output from a cleaned database:

| name | status | message |
| autoload-options-size | success | Autoloaded options size (252.79kb) is less than threshold (900kb). |

The size will of course also differ depending on the size of the WordPress site and/or if it is a network installation.