You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WordPress加载缓慢求助:load_plugin_textdomain等函数耗时超60%

Troubleshooting Slow WordPress Translation Loading (load_plugin_textdomain/load_default_textdomain)

Hey there, sorry to hear you're stuck with this 3-second load time tied directly to translation functions—let's break down the most likely fixes for your issue:

1. Optimize Your MO File Integrity & Size

Corrupted or bloated .mo files are a common culprit here. Even if your .po looks fine, auto-generated .mo files can sometimes carry redundant data or formatting that slows parsing. Try these steps:

  • Recompile your .po to .mo using the official msgfmt tool (part of gettext utilities) instead of relying on third-party generators:
    msgfmt -o cs_CZ.mo cs_CZ.po
    
  • Audit your .po file for unused entries (like deprecated plugin strings or debug text) and delete them before recompiling—fewer entries mean faster parsing.

2. Add Translation Caching

WordPress doesn't cache translation data by default, so every page load re-parses the entire .mo file. You can add custom caching via your theme's functions.php to store parsed translations in WordPress object cache:

add_filter('override_load_textdomain', function($override, $domain, $mofile) {
    // Replace 'your-domain' with your theme/plugin's text domain
    if ($domain === 'your-domain') {
        $cache_key = 'translations_' . md5($mofile);
        $cached_translations = wp_cache_get($cache_key);

        if ($cached_translations) {
            // Use cached translations instead of reloading the MO file
            global $l10n;
            $l10n[$domain] = $cached_translations;
            return true;
        }

        // Load and cache the translations if not already cached
        $translations = load_textdomain($domain, $mofile);
        if ($translations) {
            wp_cache_set($cache_key, $translations, '', 86400); // Cache for 24 hours
        }
    }
    return $override;
}, 10, 3);

If you're using a persistent object cache (like Redis or Memcached), this will give even bigger performance gains.

3. Track Down Duplicate Load Calls

Sometimes plugins or themes accidentally call load_plugin_textdomain multiple times for the same text domain, forcing WordPress to re-parse the MO file repeatedly. Use xDebug's call stack to:

  • Identify which scripts are triggering these functions
  • Check if you can remove redundant calls (e.g., a plugin loading its translation both on init and plugins_loaded)

4. Verify File System Performance

Even though both local and production are slow, double-check that your .mo file isn't stored on a slow filesystem (like a network share for production, or a fragmented local drive). Try:

  • Moving the MO file to a directory with faster read speeds
  • Ensuring file permissions are set correctly (no extra overhead from permission checks)

5. Test with Minimal Environment

Disable all non-essential plugins and switch to a default theme (like Twenty Twenty-Four) to see if the load time drops. If it does, re-enable plugins one by one to find if a specific plugin is conflicting with the translation loading process.

Once you've tried these steps, use tools like Query Monitor to re-measure the time spent on translation functions—you should see a significant drop if the issue was tied to one of these causes.

内容的提问来源于stack exchange,提问作者Kryštof Matěj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:50:44