作為一個 WordPress 主題開發者,我們都知道在 WordPress 主題中 style.css 會設定主題名稱、URL、描述、作者、版本等等信息,而為了開發和使用的便捷性很多時候我們需要在主題其它地方調用這些信息,所以這時候就可以直接使用 WordPress 提供的 wp_get_theme()函數來獲取當前主題信息。
來源于:
https://zhan.leiue.com/wordpress-wp_get_theme.html
$theme = wp_get_theme( $stylesheet, $theme_root );
- $stylesheet,主題的目錄名稱(字符串)(可選),默認為當前主題。
- $theme_root,要查看的主題根的絕對路徑(字符串)(可選)。如果未指定,將使用 get_raw_theme_root()返回的值。
$theme = wp_get_theme();
echo $theme->get( 'Name' );//主題名
echo $theme->get( ThemeURI' );//主題 URL
echo $theme->get( Description' );//主題描述
echo $theme->get( Author' );//作者名
?>
wp_get_theme()函數詳細參數:
- Name:主題名
- ThemeURI:主題 URL
- Description:主題描述
- Author:作者名
- AuthorURI:作者 URL
- Version:主題版本號
- Template:父主題的文件夾名稱,子主題中使用
- Status:主題狀態,如果發布的話
- Tags:標簽
- TextDomain:主題中用于翻譯目的的文本域
- DomainPath:主題翻譯文件路徑
當然啦,wp_get_theme 函數還可以指定主題名來獲取指定主題的其它信息,如下:
$theme = wp_get_theme( 'Fanly' );
if ( $theme->exists() )
echo $theme;