从Wordpress中的style.css文件获取主题信息
问题描述:
使用Wordpress主题,需要将信息添加到style.css文件的顶部:从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]);
?>
+0
如何在没有Wordpress功能的情况下阅读外部style.css信息? – Gino 2016-04-27 03:08:39
答
注意get_theme_data
功能已被废弃在WP 3.4,并与wp_get_theme
取代。替换函数不会检索styles.css
中的所有相同元素,因为get_theme_data
的确具有此功能,具体而言,ThemeURI
元素现在返回主题的目录,而不是Theme URL
的值。
正是我所需要的。谢谢。 – Abizern 2009-12-03 16:53:56