Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress How to Build a WordPress Theme Preparing to Code WordPress Templates Theme Images Directory

Dominic Ho
Dominic Ho
8,256 Points

Whats the difference between get_template_directory_uri() and bloginfo('template_directory')?

They seem to do the same thing, is there any reason why we should use bloginfo to link to theme images instead if get_template_directory_uri()?

1 Answer

Mackenzie Child
Mackenzie Child
4,468 Points

They're both, for the most part the same. get_template_directory_uri() however, doesn't echo the output by default. You would have to explicitly state it.

For example;

<img src="<?php bloginfo('template_directory'); ?>/images/logo.png">
// This will output <img src="example.com/wp-content/themes/themename/images/logo.png">

<img src="<?php get_template_directory_uri(); ?>/images/logo.png">
// This will output <img src="/images/logo.png">

// unless you explicitly echo it out

<img src="<?php echo get_template_directory_uri(); ?>/images/logo.png">
// This will output <img src="example.com/wp-content/themes/themename/images/logo.png">

Hope this helps :)