WordPress Constants
There a few helpful constants defined in WordPress for theme developers. TEMPLATEPATH is defined as get_template_directory(), and STYLESHEETPATH is defined as get_stylesheet_directory().
The function call and the constant are actually interchangeable with each other, but by using the constants (TEMPLATEPATH & STYLESHEETPATH) rather than the functions each time, you’ll reduce the amount of database queries and speed up your site.
TEMPLATEPATH
This returns the path to the template files of a theme. If a child theme is activated, this path will still point to the parent theme. An example path would be “/var/www/html/mysite/wp-content/themes/parenttheme”. You would most likely use this call to include a file. Example code in the functions.php file:
require_once(TEMPLATEPATH . '/extensions/theme-options.php');bloginfo(‘template_directory’);
bloginfo(‘template_directory’) returns the URL of the template directory. An example of this would be “http://mysite.com/multisite1/wp-content/themes/parenttheme”. This could be used to call a stylesheet or an image file. If a child theme is activated, this still returns the parent template directory. Example code in the header.php file:
<!--[if IE 6]><link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo('template_directory'); ?>/css/ie6.css" /><![endif]-->STYLESHEETPATH
This returns the stylesheet path to the template files of a theme. If a child theme is activated, this path will point to the child theme directory. An example path would be “/var/www/html/mysite/wp-content/themes/childtheme”. You would most likely use this call to include a file that you are sure is present in a child theme, or to check if it is. Example code in the functions.php file:
require_once(STYLESHEETPATH . '/extensions/theme-options.php');get_bloginfo(‘stylesheet_directory’)
bloginfo(‘stylesheet_directory’) returns the URL of the child template directory. An example of this would be “http://mysite.com/multisite1/wp-content/themes/childtheme”. This could be used to call a stylesheet or an image file in a child theme. Example code in the header.php file:
<!--[if IE 6]><link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo('stylesheet_directory'); ?>/css/ie6.css" /><![endif]-->Define Your Own Constants
If your theme required a lot of calls to get_bloginfo(‘stylesheet_directory’), you should define this as a new constant to reduce database calls and make your code easier to read. To do this, place the following snippet in your functions.php file (it works in child themes as well):
define('STYLESHEET_DIR', get_bloginfo('stylesheet_directory'));To retrieve the URL, you can use this anywhere in your theme:
<?php echo STYLESHEET_DIR; ?>



