Using get_theme_data() when Developing a Custom Theme for WordPress

If you are building a custom theme that you would like to add to the WordPress directory or start to sell online somewhere, a great function that can help you out is get_theme_data(). What exactly does it do? It gathers all the theme information that you were supposed to add to the style.css file so you can use it throughout your theme.

If you download a copy of Magazine Basic, you can see it in action in the functions.php file, right at the top. To make sure it is working, though, you have to have your style.css file setup correctly. The top of that file should look something like this:

/*
Theme Name: Magazine Basic
Theme URI: http://themes.bavotasan.com/our-themes/basic-themes/magazine-basic
Description: Built for WordPress 3.0. A magazine style theme with a fully customizable layout. Theme options include site width, 1 or 2 widgetized sidebars, header logo, multiple front page grid layouts, new WP 3.0 menu system, Google Analytics, pagination, drop-down menus and tons more. Also includes dynamic SEO keywords and site descriptions. Tested in Firefox 3.6, IE 7 & 8 and Safari 4. Fully optimized for search engine ranking. Translation ready. 100% valid xHTML. Designed by Themes by bavotasan.com.
Version: 2.6.7
Author: c.bavota
Author URI: http://themes.bavotasan.com/
Tags: right-sidebar,left-sidebar,fixed-width,three-columns,two-columns,white,custom-header,theme-options
	The CSS, XHTML and design is released under GPL:
	http://www.opensource.org/licenses/gpl-license.php
*/

This is all information that you can now use with get_theme_data(). I use it in Magazine Basic like so:

$bavotasan_theme_data = get_theme_data(TEMPLATEPATH.'/style.css');

With that in my functions.php file, I can use the array of data that it provides like so:

$bavotasan_theme_data = get_theme_data(TEMPLATEPATH.'/style.css');
define('THEME_NAME', $bavotasan_theme_data['Name']);
define('THEME_AUTHOR', $bavotasan_theme_data['Author']);
define('THEME_HOMEPAGE', $bavotasan_theme_data['URI']);
define('THEME_VERSION', trim($bavotasan_theme_data['Version']));

If you are not familiar with the define() function, check out Defining a Constant with PHP.
Now you can use those four constants throughout your theme. Here are some examples that I use:
In footer.php:

  Themes by bavotasan.com.

In functions.php:

echo '

';

You can also get the description and the tags. Check out the Codex for a little more info.

Share this:

Email
Facebook
Twitter
Pinterest
Pocket

Premium Themes for WordPress

Looking for an easy-to-use Premium Theme for WordPress? Check out Themes by bavotasan.com and have your site up and running in no time.

Use this WordPress website builder to build powerful websites in no time for your or your clients.

WordPress Hosting

WP Engine – designed from the ground-up to support and enhance the workflow of web designers.

Bluehost – providing quality web hosting solutions since 1996.

About the author

Picture of Luke Perrie

Luke Perrie