register_theme_directory

函数
register_theme_directory ( $directory )
参数
  • (string) $directory Either the full filesystem path to a theme folder or a folder within WP_CONTENT_DIR.
    Required:
返回值
  • (bool) True if successfully registered a directory that contains themes, false if the directory does not exist.
定义位置
相关方法
search_theme_directoriesget_template_directoryregister_theme_featureget_stylesheet_directorywp_is_theme_directory_ignored
引入
2.9.0
弃用
-

register_theme_directory: 这个函数是用来注册一个新的目录来存储主题: 当你想在默认的/wp-content/themes目录之外的一个自定义目录中存储主题时,这很有用。你可以在你的function.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;
}

常见问题

FAQs
查看更多 >