Getting WordPress Theme Stylesheet Information

5,355 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 organized it and am reposting it here to share with those who need to write their own WordPress themes. You can use it as a reference.

Example

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, I'll show you how to call it from within a template.

1、Get the name of the current theme

PHP
<?php
echo wp_get_theme();
?>

2、Get the name of another theme

PHP
<?php
$my_theme = wp_get_theme( 'twentyten' );
if ( $my_theme->exists() )
    echo $my_theme;
?>

3、Get the version number of the current theme

PHP
<?php
$my_theme = wp_get_theme();
echo $my_theme->get( 'Name' ) . " is version " . $my_theme->get( 'Version' );
?>

4、Display the current author's link

PHP
<?php
$my_theme = wp_get_theme();
echo $my_theme->get( 'AuthorURI' );
?>

For more information, please read the official WordPress wp_get_theme() documentation!

Comments

(1)
  1. Firefox 69 Windows 10

    nice share! boy~

Leave a comment

© 2026 Carefree. All rights reserved.

Carefree is a personal site about technology and everyday life, documenting web development, backend, and DevOps practices, plus software tools, digital experiences, and thoughts beyond code.