register_theme_directory() WordPress Function

The register_theme_directory() function allows you to add new directories to the list of places where Wordpress will look for themes. This can be useful if you want to keep your themes in a separate location from the default themes directory, or if you want to share themes between multiple Wordpress installations.

register_theme_directory( string $directory ) #

Registers a directory that contains themes.


Parameters

$directory

(string)(Required)Either the full filesystem path to a theme folder or a folder within WP_CONTENT_DIR.


Top ↑

Return

(bool) True if successfully registered a directory that contains themes, false if the directory does not exist.


Top ↑

Source

File: wp-includes/theme.php

function register_theme_directory( $directory ) {
	global $wp_theme_directories;

	if ( ! file_exists( $directory ) ) {
		// Try prepending as the theme directory could be relative to the content directory.
		$directory = WP_CONTENT_DIR . '/' . $directory;
		// If this directory does not exist, return and do not register.
		if ( ! file_exists( $directory ) ) {
			return false;
		}
	}

	if ( ! is_array( $wp_theme_directories ) ) {
		$wp_theme_directories = array();
	}

	$untrailed = untrailingslashit( $directory );
	if ( ! empty( $untrailed ) && ! in_array( $untrailed, $wp_theme_directories, true ) ) {
		$wp_theme_directories[] = $untrailed;
	}

	return true;
}


Top ↑

Changelog

Changelog
VersionDescription
2.9.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.

Show More