Skip to content

WordPress Translation Loading Too Early After 6.7 Update

Problem Statement

After updating to WordPress 6.7 or later, you may see a PHP notice like:

php
Notice: Function _load_textdomain_just_in_time was called incorrectly.
Translation loading for the blahblah domain was triggered too early.
This is usually an indicator for some code in the plugin or theme running too early.
Translations should be loaded at the init action or later.
in /wp-includes/functions.php on line 6114

This error occurs when translation functions (__(), _e(), etc.) are executed before WordPress has fully initialized its translation system. The error message specifically identifies the problematic text domain ("blahblah" in this example) and indicates that the code triggering it is running earlier than allowed. WordPress 6.7 introduced this notice to enforce proper translation loading timing.

Solutions

For Website Owners

  1. Update themes and plugins: Most reputable developers have fixed this issue in their code
  2. Identify the problematic component: Look for the text domain mentioned in the error message (e.g., "blahblah") to pinpoint the responsible theme/plugin
  3. Report to developers: Contact the theme/plugin author with the error details
  4. Temporary workaround: Set WP_DEBUG to false in wp-config.php (hides but doesn't fix):
    php
    define('WP_DEBUG', false);

For Theme/Plugin Developers

1. Load Text Domains at the Right Time

Ensure your translation loading uses the init hook (for plugins) or after_setup_theme hook (for themes):

Incorrect Approach:

php
// Runs too early (e.g., plugins_loaded hook)
add_action('plugins_loaded', function() {
    load_plugin_textdomain('your-textdomain', false, '/plugin/path/languages/');
});

Correct Approach:

php
// Proper implementation using init hook
add_action('init', function() {
    load_plugin_textdomain('your-textdomain', false, '/plugin/path/languages/');
});

// For themes
add_action('after_setup_theme', function() {
    load_theme_textdomain('your-textdomain', get_template_directory() . '/languages');
});

2. Handle get_plugin_data() Properly

Use get_plugin_data() only after init or disable its translation capability:

php
// Disable translations in get_plugin_data (third parameter)
$plugin_data = get_plugin_data(__FILE__, false, false);

// Alternative using get_file_data()
$plugin_headers = get_file_data(
    __FILE__, 
    ['Version' => 'Version'],   // Only get Version header
    false                      // Don't load translations
);
$version = $plugin_headers['Version'];

3. Inspect Early Translation Calls

To find where translations are called too early:

  1. Open wp-includes/l10n.php
  2. Find the _load_textdomain_just_in_time() function
  3. Add before _doing_it_wrong() call:
php
if ($domain === "your-textdomain") {
    // Capture backtrace when your text domain is called early
    error_log("EARLY TRANSLATION: " . print_r(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), true));
}

WARNING

Modifying core files is strictly for debugging! Remove changes immediately after identifying the issue.

If you must eliminate the error temporarily:

php
// Replace translated string with plain text
'footer_text' => 'All rights reserved.', 

// Instead of:
// 'footer_text' => __('All rights reserved.', 'your-textdomain'),

Best Practices

  1. All translation-related operations should happen during init or later
  2. Avoid using translation functions in constant definitions or at global scope
  3. Move late-initialization logic to wp_loaded hook if needed
  4. When querying plugin data, always disable translations if using early hooks

Additional Resources