wp_get_theme:獲得當前主題或指定主題的信息。
語法
<?php $theme = wp_get_theme( $stylesheet, $theme_root ); ?>
在 WordPress 主題中 style.css 會設定主題名稱、URL、描述、作者、版本等等信息,而為了開發和使用的便捷性很多時候我們需要在主題其它地方調用這些信息,所以這時候就可以直接使用 WordPress 提供的 wp_get_theme()函數來獲取當前主題信息。
參數
$stylesheet,主題的目錄名稱(字符串)(可選),默認為當前主題。 |
$theme_root,要查看的主題根的絕對路徑(字符串)(可選)。如果未指定,將使用 get_raw_theme_root()返回的值。 |
舉例:
<?php
$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 函數還可以指定主題名來獲取指定主題的其它信息,如下:
<?php
$theme = wp_get_theme( 'Fanly' );
if ( $theme->exists() )
echo $theme;
?>
相關
- get_theme
- get_themes
- wp_get_theme
- wp_get_themes
發表評論
要發表評論,您必須先登錄。