1. 主页
  2. 文档
  3. WordPress函数
  4. wp_get_theme

wp_get_theme

定义

wp_get_theme 获取主题信息

在 WordPress 主题中 style.css 会设定主题名称、URL、描述、作者、版本等等信息,而为了开发和使用的便捷性很多时候我们需要在主题其它地方调用这些信息,所以这时候就可以直接使用 WordPress 提供的 wp_get_theme()函数来获取当前主题信息。

语法

<?php $theme = wp_get_theme( $stylesheet, $theme_root ); ?>

参数

$stylesheet,主题的目录名称(字符串)(可选),默认为当前主题。
$theme_root,要查看的主题根的绝对路径(字符串)(可选)。如果未指定,将使用 get_raw_theme_root()返回的值。

返回值

(WP_Theme) 主题对象。 如果不知道主题是否存在,请使用主题对象的 exists()方法判断。

举例:

<?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
这篇文章对您有用吗?

我们要如何帮助您?