Load Your Own Translation Files First
Looks for custom .mo files in wp-content/languages/custom/ before the official ones, so your edited translations of a plugin or theme survive updates.
Opens WPIDE on
Code
add_filter( 'load_textdomain_mofile', function ( $mofile, $domain ) {
static $loading = array();
if ( isset( $loading[ $domain ] ) ) {
return $mofile;
}
$custom = WP_LANG_DIR . '/custom/' . $domain . '-' . determine_locale() . '.mo';
if ( is_readable( $custom ) ) {
$loading[ $domain ] = true;
load_textdomain( $domain, $custom ); // Loaded first, so its strings take priority.
unset( $loading[ $domain ] );
}
return $mofile;
}, 10, 2 );
Notes
Name files like plugin-slug-fr_FR.mo (or theme-slug-de_DE.mo) and upload them to wp-content/languages/custom/. Strings missing from your file still come from the official translation.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.