wordpress - What is the better way to retrieve URL of the template directory: bloginfo('template_url') or echo esc_url( get_template_directory_uri() )? -


using theme check test quality of theme, return theme using bloginfo();
ex: <img src="<?php bloginfo('template_url'); ?>/static/img/logo.svg"

the theme check recommended replace bloginfo() echo esc_url( get_template_directory_uri() );

i searched it, i'm not sure if using function practice.

so, it's correct use echo esc_url( get_template_directory_uri() ); call files in theme?

bloginfo('template_url') calls get_bloginfo('template_url', 'display') , function retrieves output of get_template_directory_uri().

so using get_template_directory_uri() directly reduce 2 function calls.

i don't know if use esc_url() make sense here. function get_template_directory_uri() has own little part clean url's:

$template = str_replace( '%2f', '/', rawurlencode( get_template() ) ); 

source: get_template_directory_uri()


in startertheme _s automatic (the company behind wordpress), use get_template_directory_uri() directly without esc_url().

look here: functions.php


my recommendation:

<img src="<?php echo get_template_directory_uri(); ?>/static/img/logo.svg"


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -