WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was reading this article: Common WordPress Development Mistakes and How to Fix Them, and in it, they author says:

Getting the theme location: If you are using TEMPLATEPATH or bloginfo( 'template_directory'). Stop! You should be using the very useful get_template_directory() as seen in my examples above.

But he doesn't elaborate. What's so bad about bloginfo()?

share|improve this question
up vote 15 down vote accepted

To make a long story short: get_bloginfo( 'template_directory' ) and get_bloginfo( 'template_url' ) simply return get_template_directory_uri().

So, you can shortcut that second call simply by referring directly to the latter template tag.

Refer to source for get_bloginfo().

A few others:

  • 'url' => home_url()
  • 'wpurl' => site_url()
  • 'stylesheet_url' => get_stylesheet_uri()
  • 'stylesheet_directory' => get_stylesheet_directory_uri()
  • 'locale' => get_locale()


Note also: TEMPLATEPATH and STYLESHEETPATH are slated for deprecation, so you are better off simply replacing them now, with get_template_directory() and get_stylesheet_directory(), respectively.

Edit 2

Re: this comment

Just what I was about to say :). I'd add that get_template_directory() returns the path and get_template_directory_uri() the url. So the author isn't being consistent: get_bloginfo( 'template_directory' ) and get_template_directory() return different things!

Refer back to source :)

case 'template_directory':
case 'template_url':
    $output = get_template_directory_uri();

Re: this comment:

The one caveat when developing child themes you'll need to use get_stylesheet_directory() explicitly. Someone correct me if I'm wrong.

True, but that's always been the case. get_bloginfo() doesn't return anything related to get_stylesheet_directory(). It only returns get_stylesheet_uri() and get_stylesheet_directory_uri().

share|improve this answer
The one caveat when developing child themes you'll need to use get_stylesheet_directory() explicitly. Someone correct me if I'm wrong. – Stephen Nov 15 '12 at 17:47
Thanks! I just wonder why WP has so many of these functions that just call another function, that we are then supposed to not use... – coopersita Nov 15 '12 at 19:07
In this case, I think that the reason is simply to maintain backward compatibility to the get_bloginfo() parameters. – Chip Bennett Nov 15 '12 at 19:20

protected by toscho Sep 18 '15 at 14:55

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.