Reading the data in the header of a theme's style.css
A theme's style.css file starts with a long comment holding a collection of information about the theme itself. Let's find out what theme metadata is and which functions let us retrieve it.

Contents
- What does the style.css header contain
- What is metadata?
- How do we read the theme's metadata?
- Which functions let us read theme metadata?
- get_file_data()
- wp_get_theme()
- How do I use the theme's metadata?
What does the style.css header contain
Every WordPress theme must contain a style.css file.
The style.css file starts with a comment holding information that WordPress uses to display the theme in its menus. It is also used by the WordPress theme directory to organise themes and make them easier to search.
What is metadata?
Metadata is information that describes another collection of information.
It sounds a bit redundant, but a simple example makes it easy to understand: besides the picture itself in numeric form, digital images contain metadata.
This metadata includes the camera model that took the picture, the aperture, the exposure time and other information that describes the image without being the image itself.
In the case of digital images, data and metadata live together in the same container: the image file.
How do we read the theme's metadata?
The general structure of the information contained in style.css is shown in this snippet:
/**
* Key1: Value1
* Key2: Value2
* ...
* KeyN: ValueN
*/Plugin metadata, which we will look at in a future article, uses the same structure.
Which functions let us read theme metadata?
The information at the top of style.css can be read in PHP through functions in the WordPress core.
get_file_data()
The generic get_file_data() function takes the path of a file and reads a header formatted like this:
/**
* Key1: Value1
* Key2: Value2
* ...
* KeyN: ValueN
*/and returns an associative array:
<?php
/* ... */
array(
'Key1' => 'Value1',
'Key2' => 'Value2',
...
'KeyN' => 'ValueN',
)To learn more, see get_file_data().
wp_get_theme()
The other function is wp_get_theme(), which is specific to theme metadata. It retrieves the data at the top of the style.css file and returns an object; you can access the information through the get() method of the WP_Theme object:
<?php
/* ... */
$the_theme = wp_get_theme();
$value = $the_theme->get( 'Key2' );
echo $value; // prints Value2This way you can access all the information written at the top of style.css.
If you want to dig deeper, the best source of information is the wordpress.org developer page dedicated to the Main Stylesheet.
How do I use the theme's metadata?
Here is a quick, simple, practical example.
During development and after going live you can use the Version field of the metadata to force the cache and/or CDN to be cleared, because this field can easily be appended as a query string to JS and CSS resources by the wp_enqueue_style and wp_enqueue_script functions.
With this simple trick you can force browser caches to refresh as well, so your users don't have to wait to see the changes you have just finished!
This data is where WordPress takes the information shown in the "Appearance > Themes" screen, and wordpress.org uses it to catalogue the themes it hosts.
There is also a get_theme_data function, but it has been deprecated since WordPress 3.0.4 and its use is discouraged.
If you look at the code you will see it is just a compatibility layer that lets theme and plugin developers move gradually to the new function.