我们在 Style.css 中都会填入自己的主题信息,例如名称或版本号等,以便 WordPress 展现给用户。以下是WP官方 2018 主题的注释:
/* Theme Name: Twenty Seventeen Theme URI: https://wordpress.org/themes/twentyseventeen/ Author: the WordPress team Author URI: https://wordpress.org/ Description: Twenty Seventeen brings your site to life with header video and immersive featured images. With a focus on business sites, it features multiple sections on the front page as well as widgets, navigation and social menus, a logo, and more. Personalize its asymmetrical grid with a custom color scheme and showcase your multimedia content with post formats. Our default theme for 2017 works great in many languages, for any abilities, and on any device. Version: 1.7 License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Text Domain: twentyseventeen Tags: one-column, two-columns, right-sidebar, flexible-header, accessibility-ready, custom-colors, custom-header, custom-menu, custom-logo, editor-style, featured-images, footer-widgets, post-formats, rtl-language-support, sticky-post, theme-options, threaded-comments, translation-ready 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() 文档
本站所有文章,如无特殊说明或标注,均为本站原创发布。
任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。
如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。