Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 8 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()

Edit

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();
    break;

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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