Nodejs and NPM have made life so easier. If you use Gulp toolkit with it I am sure you love it 😍 However, I came...
How to fix “_load_textdomain_just_in_time was called incorrectly” Notice in WordPress
WordPress 6.7 introduced major improvements in internationalization (i18n) and text-domain loading.
If you are a WordPress developer or user, you may have come across this notice after updating to WordPress 6.7 or later.
Notice: Function _load_textdomain_just_in_time was called incorrectly.
First Attempts to Fix (That Didn’t Work)
- Re-register the text domain at
init
orplugins_loaded
hook. - Use
load_*_textdomain()
with custom paths. - Remove duplicate calls to text-domain loading.
The Problem (Timing Is Everything)
Since WordPress 4.6 the plugins and themes no longer need load_plugin_textdomain()
or load_theme_textdomain()
functions. WordPress automatically loads the translations when needed. For more details refer to this WordPress 6.7 release note.
Actually the root cause of this issue occurs when:
- Any code runs or file is included before loading the textdomain
- That piece of code or included file uses a gettext function like
__()
,_e()
or any other gettext functions which automatically loads the text-domain - Your code afterwards tries to load the same text-domain manually to support older (than 4.6) WordPress version
The Solution
1) Straight and Easy:
If your theme or plugin doesn’t support WordPress version older than 4.6 then simply remove the load_*_textdomain()
call.
2) Disable Auto Registration
Disable the WordPress auto registration for that specific text-domain right before loading the theme or plugin’s translation. Means before load_*_textdomain
call.
function disable_textdomain_autoregistration() {
// Change: 'textdomain-name' here with yours.
$text_domain_name = 'textdomain-name';
if ( isset( $GLOBALS['wp_textdomain_registry'] ) ) {
try {
$registry = $GLOBALS['wp_textdomain_registry'];
$reflection = new ReflectionClass( $registry );
if ( $reflection->hasProperty( 'custom_paths' ) ) {
$prop = $reflection->getProperty( 'custom_paths' );
$prop->setAccessible( true );
$custom_paths = $prop->getValue( $registry );
if ( isset( $custom_paths[ $text_domain_name ] ) ) {
unset( $custom_paths[ $text_domain_name ] );
$prop->setValue( $registry, $custom_paths );
}
$prop->setAccessible( false );
}
} catch ( Exception $e ) {
// Optional: log or fail silently
error_log( 'Textdomain registry reflection error: ' . $e->getMessage() );
}
}
}
So the final implementation should look like this:
disable_textdomain_autoregistration();
load_plugin_textdomain( 'textdomain-name', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
Important: Replace textdomain-name
with your actual text-domain name in both code snippets.
This solution has worked for me consistently. However, as always with WordPress development your way may vary based on your specific setup and requirements. In that case you can post a comment and I will try to help you out 🙂