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:
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
- Update themes and plugins: Most reputable developers have fixed this issue in their code
- Identify the problematic component: Look for the text domain mentioned in the error message (e.g., "blahblah") to pinpoint the responsible theme/plugin
- Report to developers: Contact the theme/plugin author with the error details
- Temporary workaround: Set
WP_DEBUG
tofalse
inwp-config.php
(hides but doesn't fix):phpdefine('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:
// Runs too early (e.g., plugins_loaded hook)
add_action('plugins_loaded', function() {
load_plugin_textdomain('your-textdomain', false, '/plugin/path/languages/');
});
Correct Approach:
// 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:
// 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:
- Open
wp-includes/l10n.php
- Find the
_load_textdomain_just_in_time()
function - Add before
_doing_it_wrong()
call:
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.
Temporary Solution (Not Recommended)
If you must eliminate the error temporarily:
// Replace translated string with plain text
'footer_text' => 'All rights reserved.',
// Instead of:
// 'footer_text' => __('All rights reserved.', 'your-textdomain'),
Best Practices
- All translation-related operations should happen during
init
or later - Avoid using translation functions in constant definitions or at global scope
- Move late-initialization logic to
wp_loaded
hook if needed - When querying plugin data, always disable translations if using early hooks