Wordpress 检索模板目录URL的更好方法是什么:bloginfo(';template_URL';)还是echo esc_URL(get#template_directory_uri())?
使用测试我的主题的质量,它返回我的主题使用Wordpress 检索模板目录URL的更好方法是什么:bloginfo(';template_URL';)还是echo esc_URL(get#template_directory_uri())?,wordpress,wordpress-theming,Wordpress,Wordpress Theming,使用测试我的主题的质量,它返回我的主题使用bloginfo()例如:/static/img/logo.svg“ 主题检查建议我为echo esc\u url(get\u template\u directory\u uri())替换bloginfo(); 我搜索了一下,但是我不确定使用这个函数是否是一个好的实践 因此,使用echo esc_url(get_template_directory_uri());调用我主题中的任何文件是正确的?bloginfo('template_url')调用get
bloginfo()代码>
例如:/static/img/logo.svg“
主题检查建议我为echo esc\u url(get\u template\u directory\u uri())替换bloginfo()
;
我搜索了一下,但是我不确定使用这个函数是否是一个好的实践
因此,使用echo esc_url(get_template_directory_uri());
调用我主题中的任何文件是正确的?bloginfo('template_url')
调用get_bloginfo('template_url','display')
,该函数检索get_template_directory_uri()的输出
因此,直接使用get\u template\u directory\u uri()
将减少2个函数调用
我不知道在这里使用esc\u url()
是否有意义。函数get\u template\u directory\u uri()
有自己的一小部分来清理url:
$template = str_replace( '%2F', '/', rawurlencode( get_template() ) );
资料来源:
在(wordpress背后的公司)的Starter主题中,他们直接使用get\u template\u directory\u uri()
,而不使用esc\u url()
看这里:
我的建议是:
/static/img/logo.svg“
bloginfo('template\u url')
内部使用get\u template\u directory\u uri()
因此,最好使用get\u template\u directory\u uri()
访问主题文件夹中的文件
使用esc_rul清理URL是一个很好的实践
清理url时始终使用esc_url(在文本节点中,属性
节点或任何其他位置)。拒绝不包含以下内容之一的URL:
提供了白名单协议(默认为http、https、ftp、ftps、,
mailto、news、irc、gopher、nntp、feed和telnet),消除了无效的
字符,并删除危险字符
有关更多详细信息,请参阅以下链接: