1. 首页
  2. WordPress 函数手册

register_theme_directory()

register_theme_directory( string $directory )

注册包含主题的目录。
Register a directory that contains themes.

目录锚点:#参数#返回#源码#笔记


参数(Parameters)

参数 类型 必填 说明
$directory (string) 必需 主题文件夹的完整文件系统路径或WP_CONTENT_DIR中的文件夹

返回(Return)

(bool)


源码(Source)

/**
 * Register a directory that contains themes.
 *
 * @since 2.9.0
 *
 * @global array $wp_theme_directories
 *
 * @param string $directory Either the full filesystem path to a theme folder or a folder within WP_CONTENT_DIR
 * @return bool
 */
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;
}
更新版本 源码位置 使用 被使用
2.9.0 wp-includes/theme.php:397 0 1 function

笔记(Notes)

例子

register_theme_directory() 为WP2原创文章,链接:https://www.wp2.cn/functions/register_theme_directory/