SFW

Reduce autoload wpseo_taxonomy_meta

Reduce autoload wpseo_taxonomy_meta size option in WordPress New

()

WordPress wpseo_taxonomy_meta autoload: its management is critical for website performance and scales as your content does. It is an option used by the Yoast SEO plugin to store metadata of taxonomies such as categories and tags. The issue is that when this is too large—over 800KB—it may reduce performance and trigger warnings.

Understanding the Impact on Website Performance

By default, WordPress will load all autoloaded options into memory on every page request which may affect the overall website speed. This means that if the wpseo_taxonomy_meta becomes bloated, it can be very resource-intensive and slow down your site. This is not sustainable on large websites with a lot of taxonomies, as the system will struggle to handle the load efficiently.

Challenges with Yoast SEO

Many users have complained about the ever-increasing size of wpseo_taxonomy_meta. Yoast SEO has failed to provide a sure solution to this problem despite numerous complaints and support requests. The plugin keeps on accumulating data with time, including entries for deleted taxonomies, without cleaning up itself. This is what causes unnecessary bloat in the database.

Common Strategies for Reduction

To mitigate this issue, consider the following approaches:

  1. Manual Cleanup: Look at wpseo_taxonomy_meta entries and remove data from deleted or unused taxonomies. This requires careful handling to avoid corrupting serialized data.
  2. Clean Up Taxonomies: Clean up your taxonomies regularly to avoid duplication and irrelevant entries. This will proactively reduce data that could be stored in wpseo_taxonomy_meta.
  3. Disable Autoload: Update autoload for wpseo_taxonomy_meta to ‘no’. This will keep WordPress from loading it on each request, saving memory, but be sure this doesn’t cause problems on your site.

If you carry out step 3) above, without the below Raiday’s solution, this will critically affect your SEO as all work you have done on Yoast SEO will vanish and affect search engines optimisation visibility.

Raiday’s Solution to Manage wpseo_taxonomy_meta Autoload

Raiday proposed a practical workaround that balances performance optimization with functionality. First, set the autoload value of wpseo_taxonomy_meta to false in the database. This will prevent WordPress from loading this potentially huge option on every page request, saving a lot of server memory and speeding up the site for regular visitors. Now, add the following PHP snippet to your theme’s functions.php file or a custom plugin. This code will dynamically re-enable autoload for specific scenarios: logged-in ylusers, administrators, and bots or crawlers like Googlebot and Bingbot. By targeting only essential cases, this solution keeps your site fast for typical visitors while ensuring bots and logged-in users still get to use the full metadata load. This approach presents a smart middle ground, addressing both performance and functionality concerns.

See our code below:

//Ensure wpseo_taxonomy_meta is set to autoload = 'no'

add_filter('pre_option_wpseo_taxonomy_meta', function ($value) {
    // Check if the user is logged in or an admin
    if (is_user_logged_in() && current_user_can('manage_options')) {
        // If logged in or an admin, return the default value
        return $value;
    }

    // Check if this is a cron request
    if (defined('DOING_CRON') && DOING_CRON) {
        // If a cron job is running, return the default value
        return $value;
    }

    // Check if the request is from a bot or crawler
    $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? strtolower($_SERVER['HTTP_USER_AGENT']) : '';

    // Simplified list of generic terms to match bots, including requested additions
	$is_bot = preg_match('/(google|bing|yahoo|duckduckgo|baidu|yandex|bot|crawler|spider|curl|wget|httpclient|headless|gpt|llm|ai|ahrefs|moz|typeflow|pagespeed|web\.dev)/i', $user_agent);

    // If it's not a bot, disable autoload and fetch the option manually
    if (!$is_bot) {
        global $wpdb;

        $option_value = $wpdb->get_var($wpdb->prepare(
            "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s AND autoload = 'no'",
            'wpseo_taxonomy_meta'
        ));

        return maybe_unserialize($option_value);
    }

    // Default behavior for bots
    return $value;
});
  • Why avoid it for non-bot Users? Normal users (conversely to search engine crawlers) may not need this manual database query and metadata for their normal browsingand user interactions.
  • Why fetch manually? If an option’s autoload is set to 'no', it won’t be loaded into memory automatically on every page load. This code ensures that this specific option is fetched only when needed, optimizing memory usage and page speed load as it is skipped from any processing and parsing.

You will get the best of both worlds!

Use with Care

First, backup your database and website before implementing these changes to avoid data loss. If you are not comfortable with these tasks, please consult a developer or database administrator. These steps will help you manage the size of wpseo_taxonomy_meta, but they are workarounds, not permanent fixes. It is still hoped that Yoast SEO will resolve this problem in future updates.

How useful was this?

Click on a star to rate it!

Average rating / 5. Vote count:

No votes so far! Be the first to rate this post.

More Posts from the same Category