3

Basically I've used bloginfo(template_url) in a WordPress theme, but when I run theme-checker, it recommends to replace bloginfo(template_url) with get_template_directory_uri(), however when I use get_template_directory_uri() it doesn't work. It works fine if I use it to replace get_bloginfo(template_url) but that's not what I want now. Is bloginfo(template_url) being deprecated? If it is, what is it's replacement?

Thanks

6

bloginfo($option) echos out a value whereas get_template_directory_uri() returns a string - did you maybe forget to echo get_template_directory_uri()? Also are you passing a string with quotes i.e. bloginfo(template_url) vs bloginfo('template_url')?

Both bloginfo('template_url') and get_template_directory_uri() should work, they aren't deprecated.

  • Firstly I do need a value rather than a string, so I'm using bloginfo($option). Also, everything is working fine in my theme while using bloginfo($option). The problem I have is when I use theme-checker it recommends that I should use get_template_directory_uri() instead, but when I did, it didn't work. Should I just ignore theme-checker's recommendation? – WagnerMatosUK Jul 12 '12 at 7:43
  • I would ignore it. I personally use get_bloginfo() over get_template_directory_uri() and don't see any reason why it's better to use one function over the other – Rezen Jul 12 '12 at 16:07
  • Good to know! Just odd that theme-checker suggest a change that doesn't seem to be necessary... Anyway, thanks for the help. – WagnerMatosUK Jul 13 '12 at 8:13
4

bloginfo is a wrapper for get_bloginfo, which just calls those functions directly:

function get_bloginfo( $show = '', $filter = 'raw' ) {
    case 'stylesheet_directory':
        $output = get_stylesheet_directory_uri();
        break;
    case 'template_directory':
    case 'template_url':
        $output = get_template_directory_uri();
        break;

so it's ultimately exactly the same output.

3

This is the right way -

<?php echo get_template_directory_uri(); ?>
0

You Can use both

<?php echo get_template_directory_uri(); ?>
<?php echo get_bloginfo('template_url'); ?>
  • The echo in front of bloginfo() is not needed. – Geert Jul 12 '12 at 5:46
  • yeah..thats not needed.sorry about that.its should be get_bloginfo – Monirul Islam Jul 12 '12 at 6:02
  • The code I'm using is: <img class="big_divider" src="<?php bloginfo('template_url'); ?>/images/dividers/big_divider.png" alt="content divider" /> and is working perfectly how I wanted. The thing is that theme-checker recommends that I use get_template_directory_uri() instead which doesn't work when I did use it, so it made me wonder whether bloginfo($option) is being deprecated. If not, why is theme-checker suggesting to replace it? – WagnerMatosUK Jul 12 '12 at 7:49
-2

The correct way should be (imho)

<?php get_bloginfo('template_url'); ?>

Rationale: The function get_template_directory_uri(), besides being long, also has a slightly misleading name. It doesn't not return a directory and not a uri either (the identifier would be the theme name not it's location)

So, for typing reasons as well as self-documenting reason the get_bloginfo is better.

Replacing is not needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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