[英]Getting Theme information from the style.css file in Wordpress
对于Wordpress主题,有必要将信息添加到style.css文件的顶部:
例如; 对于默认主题,有以下内容:
/*
Theme Name: WordPress Default
Theme URI: http://wordpress.org/
Description: The default WordPress theme based on the famous <a href="http://binarybonsai.com/kubrick/">Kubrick</a>.
Version: 1.6
Author: Michael Heilemann
Author URI: http://binarybonsai.com/
Tags: blue, custom header, fixed width, two columns, widgets
*/
是否有任何wordpress函数可通过编程方式获取此信息?
您可以使用get_theme_data()
或我快速组合在一起的以下PHP脚本:
<?php
$file = file('your file location');
$contents = '';
foreach($file as $lines => $line){
$contents .= $line;
}
preg_match('!/\*[^*]*\*+([^/][^*]*\*+)*/!', $contents, $themeinfo);
echo nl2br($themeinfo[0]);
?>
请注意,在WP 3.4中已弃用了get_theme_data
函数,并用wp_get_theme
代替了该wp_get_theme
。 替换函数不会像get_theme_data
那样从styles.css
检索所有相同的元素,特别是ThemeURI
元素现在返回主题的目录,而不是Theme URL
的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.