WordPress at a glance

register_theme_directory() WP 2.9.0

Register a directory that can contain themes.

The $directory parameter specifies the path to the theme folder with no slash at the end. The specified path is added to the global array of $wp_theme_directories, which is then used when retrieving the path/URL to the WordPress themes folder.

  • Global. Array. $wp_theme_directories

No Hooks.

Return

true/false.

Usage

register_theme_directory( $directory );
$directory(string) (required)
Either the full filesystem path to a theme folder or a folder within WP_CONTENT_DIR

Examples

#1 Make the plugin folder as a folder to the WordPress themes

/*
 * For the structure of the plugin of this kind:
 * 
 * /my-plugin
 *    /my-plugin.php
 *    /themes/
 *
 * This code should be placed in the file my-plugin.php.
 */
register_theme_directory( dirname( __FILE__ ) . '/themes' );

Code of register theme directory: wp-includes/theme.php VER 5.1.1

<?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 ) ) {
		$wp_theme_directories[] = $untrailed;
	}

	return true;
}

Related Functions

From tag: theme path (theme folder url)

More from category: Other Theme Functions

No comments
    Hello, !     Log In . Register