load_theme_textdomain

Load the theme's translated strings.

Description

load_theme_textdomain( (string) $domain, (bool) $path = false ); 

If the current locale exists as a .mo file in the 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 (2)

0. $domain (string)
Text domain. Unique identifier for retrieving translated strings.
1. $path — Optional. (bool) => false
Path to the directory containing the .mo file. Default false.

Usage

  1. if ( !function_exists( 'load_theme_textdomain' ) ) { 
  2. require_once ABSPATH . WPINC . '/l10n.php'; 
  3.  
  4. // Text domain. Unique identifier for retrieving translated strings. 
  5. $domain = ''; 
  6.  
  7. // Optional. Path to the directory containing the .mo file. 
  8. // Default false. 
  9. $path = false; 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = load_theme_textdomain($domain, $path); 
  13.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/l10n.php  
  1. function load_theme_textdomain( $domain, $path = false ) { 
  2. /** 
  3. * Filters a theme's locale. 
  4. * @since 3.0.0 
  5. * @param string $locale The theme's current locale. 
  6. * @param string $domain Text domain. Unique identifier for retrieving translated strings. 
  7. */ 
  8. $locale = apply_filters( 'theme_locale', is_admin() ? get_user_locale() : get_locale(), $domain ); 
  9.  
  10. $mofile = $domain . '-' . $locale . '.mo'; 
  11.  
  12. // Try to load from the languages directory first. 
  13. if ( load_textdomain( $domain, WP_LANG_DIR . '/themes/' . $mofile ) ) { 
  14. return true; 
  15.  
  16. if ( ! $path ) { 
  17.  
  18. return load_textdomain( $domain, $path . '/' . $locale . '.mo' );