The light and dark side of the Autoload

What is the autoload?

If you open the database of your WordPress website with PHPMyAdmin and check the table wp_options, you will see something similar to the following picture

Table wp_options seen with PHPMyAdmin

Some options have the autoload set to “no” or false, and other ones to “yes” or true.

When you visit a page, WordPress loads all the options that have the autoload set to “yes” or true, with one single query, and saves the result in an internal cache. Next time when an autoloaded option is called again, it will be taken from the cache, and the database will not be queried again only for that option.

 

The light side of the Autoload

So with one single query, you get all the options that you always need. If you need the autoloaded options on all the pages, this method dramatically reduces the number of database queries.
This is the “light side” of the Autoload.

 

The dark side of the Autoload

Unfortunately, not all the plugins and themes are perfectly coded, and many of them abuse the autoload. They even use it for options that are called only in the backend, or in rare situations.
If those options are not so big, the impact will not be dramatic, but many times you may see huge autoloaded options that slow down all the pages without any need to load them everywhere.

In some situations, the plugin or the theme that introduced those options is even not active anymore, but they left that bloat in the database.

 

How to get rid of the autoloaded options that should not load everywhere

There are on the marked plugins for database optimization that give you the possibility to change the autoload, but all the plugins that we tested only remove the autoload until the same option is updated again. In other words, you can remove the autoload of an option, but when you save again that option, it will have again the autoload.

This is why we decided to add the Autoload management to FDP PRO.

If you are an FDP PRO user, you can re-assign the autoload, and FDP will ensure the autoload will not be changed next time the same option is saved into the database.
For more details about how to get rid of the autoloaded options that should not load everywhere read the documentation.

Another way to get rid of the autoloaded options that should not be autoloaded is by writing to the author of the plugin that introduces those options.

Or you can adopt the do-your-self approach.
In this case, change the autoload directly in the database with PHPMyAdmin, and then add this code to the functions.php of your child theme or a functional plugin:

add_action( 'updated_option',function( $option,$old_value,$value ){
if( in_array( $option,array( 'option_name_sample','option_name_sample2','option_name_sample3' ) ) ){
    global $wpdb;
    $result = $wpdb->update( $wpdb->options,array( 'autoload' => $autoload ), array( 'option_name' => $option ) );
}
    return $value;
},999999999,3 );

 

The code above will ensure that when an option of the array is updated, the autoload of that option will be removed.