Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 检索模板目录URL的更好方法是什么:bloginfo(';template_URL';)还是echo esc_URL(get#template_directory_uri())?_Wordpress_Wordpress Theming - Fatal编程技术网

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),消除了无效的 字符,并删除危险字符

有关更多详细信息,请参阅以下链接: