Using WordPress ‘load_child_theme_textdomain()’ PHP function

The load_child_theme_textdomain() WordPress PHP function loads the child theme’s translated strings.

Usage

load_child_theme_textdomain( $domain, $path );

Example:

load_child_theme_textdomain('my_child_theme', get_stylesheet_directory() . '/languages');

Parameters

  • $domain (string) – Text domain, a unique identifier for retrieving translated strings.
  • $path (string|false) – Optional. Path to the directory containing the .mo file. Default: false.

More information

See WordPress Developer Resources: load_child_theme_textdomain()

Note: The .mo files must be named based on the locale exactly.

Examples

Load child theme textdomain from a specific folder

Explanation: This example demonstrates how to load the child theme textdomain from a folder named languages within the child theme directory.

function my_child_theme_setup() {
    load_child_theme_textdomain('my_child_theme', get_stylesheet_directory() . '/languages');
}
add_action('after_setup_theme', 'my_child_theme_setup');

Load child theme textdomain from the child theme root folder

Explanation: This example shows how to load the child theme textdomain from the child theme’s root folder.

function my_child_theme_setup() {
    load_child_theme_textdomain('my_child_theme', get_stylesheet_directory());
}
add_action('after_setup_theme', 'my_child_theme_setup');

Load multiple child theme textdomains

Explanation: This example shows how to load multiple textdomains for a child theme.

function my_child_theme_setup() {
    load_child_theme_textdomain('my_child_theme', get_stylesheet_directory() . '/languages');
    load_child_theme_textdomain('my_child_theme_extra', get_stylesheet_directory() . '/languages/extra');
}
add_action('after_setup_theme', 'my_child_theme_setup');

Load child theme textdomain with a custom action

Explanation: This example demonstrates how to load the child theme textdomain using a custom action.

function my_child_theme_setup() {
    load_child_theme_textdomain('my_child_theme', get_stylesheet_directory() . '/languages');
}
add_action('my_custom_action', 'my_child_theme_setup');

Load child theme textdomain in a plugin

Explanation: This example shows how to load a child theme textdomain within a plugin.

function my_plugin_load_child_theme_textdomain() {
    load_child_theme_textdomain('my_child_theme', get_stylesheet_directory() . '/languages');
}
add_action('plugins_loaded', 'my_plugin_load_child_theme_textdomain');