WP_Theme::load_textdomain() WordPress Method

The load_textdomain() method is used to load a plugin or theme's textdomain. This method is typically called during the plugin's or theme's init() method. Textdomains are used to store translated strings for a plugin or theme. By default, a plugin or theme's textdomain is the same as its slug. For example, the textdomain for the "Hello Dolly" plugin is "hello-dolly". The load_textdomain() method accepts two arguments: the textdomain and the abspath to the plugin or theme's directory. The abspath is used to determine which .mo file to load. For example, the following code would load the "hello-dolly" textdomain: $theme->load_textdomain( 'hello-dolly', '/path/to/hello-dolly/' ); If the textdomain is not specified, the default textdomain will be used. The load_textdomain() method will return true if the textdomain was successfully loaded, or false if it failed.

WP_Theme::load_textdomain() #

Loads the theme’s textdomain.


Description

Translation files are not inherited from the parent theme. TODO: If this fails for the child theme, it should probably try to load the parent theme’s translations.


Top ↑

Return

(bool) True if the textdomain was successfully loaded or has already been loaded. False if no textdomain was specified in the file headers, or if the domain could not be loaded.


Top ↑

Source

File: wp-includes/class-wp-theme.php

	public function load_textdomain() {
		if ( isset( $this->textdomain_loaded ) ) {
			return $this->textdomain_loaded;
		}

		$textdomain = $this->get( 'TextDomain' );
		if ( ! $textdomain ) {
			$this->textdomain_loaded = false;
			return false;
		}

		if ( is_textdomain_loaded( $textdomain ) ) {
			$this->textdomain_loaded = true;
			return true;
		}

		$path       = $this->get_stylesheet_directory();
		$domainpath = $this->get( 'DomainPath' );
		if ( $domainpath ) {
			$path .= $domainpath;
		} else {
			$path .= '/languages';
		}

		$this->textdomain_loaded = load_theme_textdomain( $textdomain, $path );
		return $this->textdomain_loaded;
	}


Top ↑

Changelog

Changelog
VersionDescription
3.4.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.