Loading
0

WordPress教程 获取主题信息WordPress函数wp_get_theme

wp_get_theme 函数可以间接获得以后启用的主题或许指定的主题信息,包孕版本作者路径等。就主题更新功效而言,开发者只要要判定返归的主题对象中版本号是否小于最新版本号即可断定是否更新。今天WordPress主题站为大家分享一下获取主题信息WordPress函数wp_get_theme。

WordPress教程 获取主题信息WordPress函数wp_get_theme

函数组织

wp_get_theme( string $stylesheet = null,string $theme_root = null )

函数原型:

function wp_get_theme( $stylesheet = null,$theme_root = null ) {

global $wp_theme_directories;

if ( empty( $stylesheet ) ) {

$stylesheet = get_stylesheet();

}

if ( empty( $theme_root ) ) {

$theme_root = get_raw_theme_root( $stylesheet );

if ( false === $theme_root ) {

$theme_root = WP_CONTENT_DIR . '/themes';

} elseif ( ! in_array( $theme_root,(array) $wp_theme_directories ) ) {

$theme_root = WP_CONTENT_DIR . $theme_root;

}

}

return new WP_Theme( $stylesheet,$theme_root );

}

形容:得到以后主题或指定主题的信息。

参数:

$stylesheet

(string) (可选) 指定的主落款,默许以后主题。

默许值: 空

$theme_root

(string) (可选) 主题的相对路径,假如为空, 则应用 get_raw_theme_root()函数获得的路径 (默许以后主题).

默许值: 空

返归值

(WP_Theme) 主题对象。 假如不晓得主题是否存在,请应用主题对象的 exists()要领判定。

简朴应用

<?php

$my_theme = wp_get_theme( 'twentytwelve' );

if ( $my_theme->exists() )

echo esc_html( $my_theme );

?>

成果:

object(WP_Theme)[916]

public 'update' => boolean false

private 'theme_root' => string 'home/path/wp-content/themes' (length=77)

private 'headers' =>

array (size=11)

'Name' => string 'mytheme' (length=7)

'ThemeURI' => string 'http://example.com/' (length=22)

'Description' => string 'Description' (length=11)

'Author' => string 'Something Here' (length=14)

'AuthorURI' => string 'http://example.com/' (length=22)

'Version' => string '1.0.0' (length=5)

'Template' => string '' (length=0)

'Status' => string '' (length=0)

'Tags' => string 'custom-background,custom-logo,custom-menu,featured-images,threaded-comments,translation-ready' (length=98)

'TextDomain' => string 'mytheme' (length=7)

'DomainPath' => string '' (length=0)

private 'headers_sanitized' => null

private 'name_translated' => null

private 'errors' => null

private 'stylesheet' => string 'mytheme' (length=7)

private 'template' => string 'mytheme' (length=7)

private 'parent' => null

private 'theme_root_uri' => null

private 'textdomain_loaded' => null

private 'cache_hash' => string 'ca9dd01f01f2a5cb4616a776eff52690' (length=32)

以上是WordPress主题站为你网络收拾整顿的获取主题信息WordPress函数wp_get_theme详解全数内容,但愿文章可以或许帮你解决WordPress获取主题信息函数wp_get_theme详解所碰到的步伐开提问题。