Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

User:Daveshine/load child theme textdomain

Description

Loads the child theme's translated strings.

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, de_DE.mo for example.

This function is the proper way to load translations for a child theme. For the parent theme/single themes load_theme_textdomain() is used instead. Loading child theme translations extra is better to optimize the loading process and helps organize code and files better.

Example: If you are using "Twenty Eleven" as your parent theme it already comes with the function load_theme_textdomain() in place and there are already translations for this theme available in numerous languages. Now you have created a child theme for it with lots of custom elements like new sidebars or other sections. All strings of these new sections in frontend and also backend should be controlled by the child theme's translations files. If the parent theme gets updated (and most likely its language strings too...) your child theme translations keep untouched. So that's the proper way of doing it and WordPress is prepared for that out of the box.

Usage

<?php load_child_theme_textdomain$domain$path ?>

Parameters

$domain
(string) (required) Unique identifier for retrieving translated strings.
Default: None
$path
(unknown) (optional) The directory where the .mo file can be found (without the trailing slash).
Default: false

Return Values

(bool) 
This function return TRUE as textdomain well loaded, FALSE on failure.

Example

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.

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

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.

Notes

Internationalization and localization (other correct 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.

Change Log

Since: 2.9.0

Source File

load_child_theme_textdomain() is located in [1].

Related

Localization: get_locale(), load_textdomain(), load_default_textdomain(), load_plugin_textdomain(), load_theme_textdomain()

See also index of Function Reference and index of Template Tags.