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檔案或外掛中使用這個函式來註冊一個新的主題目錄。

註冊一個包含主題的目錄。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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;
}
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; }
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
檢視更多 >