How to replace bloginfo(template_url)

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

Related posts

Leave a Reply

4 comments

  1. 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.

  2. 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.