load_child_theme_textdomain( string $domain, string|false $path = false ): bool
Loads the child theme’s translated strings.
Contents
Description
If the current locale exists as a .mo file in the child theme’s root directory, it will be included in the translated strings by the $domain.
The .mo files must be named based on the locale exactly.
Parameters
-
$domain
string Required -
Text domain. Unique identifier for retrieving translated strings.
-
$path
string|false Optional -
Path to the directory containing the .mo file.
Default:
false
Return
bool True when the theme textdomain is successfully loaded, false otherwise.
More Information
Internationalization and localization (other common spellings are internationalisation and localisation) are means of adapting computer software to different languages.
- l10n is an abbreviation for localization.
- i18n 18 stands for the number of letters between the first i and last n in internationalization.
Source
File: wp-includes/l10n.php
.
View all references
function load_child_theme_textdomain( $domain, $path = false ) {
if ( ! $path ) {
$path = get_stylesheet_directory();
}
return load_theme_textdomain( $domain, $path );
}
Changelog
Version | Description |
---|---|
2.9.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
The load_child_theme_textdomain() function should generally be called from within the after_setup_theme action hook, just the same as with its related load_theme_textdomain() function.
‘my_parent_theme’ = The name of the Main theme
The .mo files must use language-only filenames, like languages/de_DE.mo in your child theme directory.
Unlike plugin language files, a name like my_child_theme-de_DE.mo will NOT work. Although plugin language files allow you to specify the text-domain in the filename, this will NOT work with themes and child themes. Language files for themes should include the language shortcut ONLY.
Might be useful for beginners to also know that in the note above
‘wpdocs_child_theme_setup’ = The name of your child theme,
hence that needs to be changed in line 4 and line 7 in the code snippet shown above.
And in that same example the .mo and .po files are not uploaded to the child-theme root, but to a folder named languages inside the child-folder.
Top ↑
Feedback
No, a beginner will try to change that function name to “parenttheme-child” and a dash is not allowed there. That function name doesn’t matter much.
You need only update the
PARENTTHEMENAME
to the parent theme directory name. Put the .MO and .PO files in a folder called ‘languages’ under the child theme directory. — By interestica —It is not needed at all to rename “wpdocs_child_theme_setup”. It is just a callback function, it can be named as you like, as long as the names of the function and second argument of add_action match. You can even do this (PHP 5.3+), without the need for a name:
add_action( 'after_setup_theme', function() { load_child_theme_textdomain( 'my_parent_theme', get_stylesheet_directory() . '/languages' ); } );
Or, from PHP 7.4+add_action( 'after_setup_theme', () => { load_child_theme_textdomain( 'my_parent_theme', get_stylesheet_directory() . '/languages' ); } );
— By Lovro Hrust —