外贸独立站的底层设计密码WordPress 成品站模板
当前位置:首页>WordPress建站>WordPress开发>WordPress 获取主题样式表 style.css 注释里的信息

WordPress 获取主题样式表 style.css 注释里的信息

我们在 Style.css 中都会填入自己的主题信息,例如名称或版本号等,以便 WordPress 展现给用户。以下是WP官方 2014 主题的注释:

/*
Theme Name: Twenty Fourteen
Theme URI: https://wordpress.org/themes/twentyfourteen
Author: the WordPress team
Author URI: https://wordpress.org/
Description: In 2014, our default theme lets you create a responsive magazine website with a sleek, modern design. Feature your favorite homepage content in either a grid or a slider. Use the three widget areas to customize your website, and change your content's layout with a full-width page template and a contributor page to show off your authors. Creating a magazine website with WordPress has never been easier.
Version: 1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: black, green, white, light, dark, two-columns, three-columns, left-sidebar, right-sidebar, fixed-layout, responsive-layout, custom-background, custom-header, custom-menu, editor-style, featured-images, flexible-header, full-width-template, microformats, post-formats, rtl-language-support, sticky-post, theme-options, translation-ready, accessibility-ready
Text Domain: twentyfourteen 

This theme, like WordPress, is licensed under the GPL.
Use it to make something cool, have fun, and share what you've learned with others.
*/

从中可以看到主题名称、主题链接、作者、作者链接、版本等等信息。在 WordPress 3.4 以上的版本中,我们可以直接使用 wp_get_theme() 这个函数来获取这些信息。以下是一些简单的例子:

获取当前主题名字:

<?php
echo wp_get_theme();
?>

获取其它主题名字:

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

获取当前主题版本号:

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

显示当前主题作者的链接:

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

更多介绍,请阅读WP官方的 wp_get_theme() 文档

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
欢迎关注WordPress大学公众号 WPDAXUE
WordPress开发

检查 PHP 和 WordPress 的最低版本

2013-12-7 9:49:48

WordPress开发

WordPress 用户没有设置菜单时显示提示语

2013-12-16 7:21:01

5 条回复 A文章作者 M管理员
  1. 博主好,请问怎样获取主题文件夹名称.非常感谢

  2. 不错的介绍

  3. Tmd

    Style.css注释信息删除掉,还获取个P

  4. 不错,新主题用上了

  5. 收了 这函数不错 以前footer都是自己手打主题信息

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索