Getting Detailed Configuration Information from a WordPress Theme's Stylesheet
5,380 1
Anyone who has tinkered with WordPress themes should know that the style.css file in the WordPress theme directory contains detailed information about the theme. So, how can you call this information from within a theme template? Don't worry—WordPress has already provided the documentation.
I have整理了一下,转载过来分享给一些需要自写 WordPress 主题的小伙伴,可以参考一下。

Example
PHP PHP
/*
Theme Name: lovexin
Theme URI: https://www.ikxin.com/lovexin-theme.html
Author: 夜色静好
Author URI: https://www.ikxin.com/
Description: HTML5 + CSS3 响应式设计,博客、杂志、图片、公司企业多种布局可选,集成 SEO 自定义功能,丰富的主题选项,众多实用小工具。
Version: 1.0
*/
The above is the style.css information for this site. Next, we'll show you how to call it from within a template.
1、Getting the name of the current theme
PHP PHP
<?php
echo wp_get_theme();
?>
2、Getting the name of another theme
PHP PHP
<?php
$my_theme = wp_get_theme( 'twentyten' );
if ( $my_theme->exists() )
echo $my_theme;
?>
3、Getting the version number of the current theme
PHP PHP
<?php
$my_theme = wp_get_theme();
echo $my_theme->get( 'Name' ) . " is version " . $my_theme->get( 'Version' );
?>
4、Displaying the current author's link
PHP PHP
<?php
$my_theme = wp_get_theme();
echo $my_theme->get( 'AuthorURI' );
?>
For more information, please read the WordPress official wp_get_theme() documentation!
Comments
(1)nice share! boy~