Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Imagine you have a style.css with these headers:
- /******************************
- * Theme Name: Theme Name
- * Theme URI: ThemeURI
- * Author: Author Name
- * Author URI: AuthorUri
- * Description: ThemeDescription
- * License: License
- * License URI: LicenseURI
- * Tags: ThemeTags
- *
- * Custom Header: Custom Value
- *
- * Custom Header Two: Custom Value
- *
- *****/
- // And you need to get the value of Custom Header and/or Custom Header Two
- // Here is a function to get standard and custom headers in style.css in WordPress Themes
- function getThemeInfo($stylesheet) {
- if(file_exists($stylesheet)) {
- $file = file($stylesheet);
- $contents = array();
- foreach ($file as $lines => $line) {
- preg_match("/\*(.*?):/s", $line, $name);
- preg_match("/:(.*)$/s", $line, $value);
- if($name && $value) {
- $contents[trim($name[1])] = trim($value[1]);
- }
- }
- return $contents;
- }else{
- return array();
- }
- }
- // Running this function on style.css with the headers specified above, would generate an array like this:
- // Array
- // (
- // [Theme Name] => Theme Name
- // [Theme URI] => ThemeURI
- // [Author] => Author Name
- // [Author URI] => AuthorUri
- // [Description] => ThemeDescription
- // [License] => License
- // [License URI] => LicenseURI
- // [Tags] => ThemeTags
- // [Custom Header] => Custom Value
- // [Custom Header Two] => Custom Value
- // )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement