0

I crate many wordpress based sites. When i need to include path to the theme folder, i use this code <?php bloginfo('template_url'); ?>. I`m Theme check plugin. And they say to me

bloginfo('template_url') was found in the file services-section.php. Use echo esc_url( get_template_directory_uri() ) instead.

What the difference between this to methods? Which is better to use?

0

‘template_url‘ / ‘template_directory‘ – URL of the active theme’s directory. Within child themes, both get_bloginfo(‘template_url’) and get_template() will return the parent theme directory. Consider echoing get_template_directory_uri() instead (for the parent template directory) or get_stylesheet_directory_uri() (for the child template directory).

Source: https://developer.wordpress.org/reference/functions/bloginfo/

the function get_template_directory_uri() is the better one, if you want to support creating child themes. if you don't care, it shouldn't matter much.

edit:

did a simple speed test and found no significant difference:

blog_info('template_url')    0.00010 sec 
get_template_directory_uri() 0.00007-0.00010 sec
  • do they have some speed difference? – wkornilow Mar 11 '16 at 17:04
  • no, added some speed test results :) – iantsch Mar 11 '16 at 18:18

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.