wordpress - 检索模板目录 : bloginfo ('template_url' ) or echo esc_url( get_template_directory_uri() )? 的 URL 的更好方法是什么

标签 wordpress wordpress-theming

使用Theme Check为了测试我的主题的质量,它返回我的主题正在使用 bloginfo();
例如:<img src="<?php bloginfo('template_url'); ?>/static/img/logo.svg"

主题检查建议我替换 bloginfo()对于 echo esc_url( get_template_directory_uri() );

我搜索过它,但我不确定使用此功能是否是一个好的做法。

所以,正确使用echo esc_url( get_template_directory_uri() );用于调用我的主题中的任何文件?

最佳答案

bloginfo('template_url')来电 get_bloginfo('template_url', 'display')该函数检索 get_template_directory_uri() 的输出.

所以使用get_template_directory_uri()直接减少2次函数调用

我不知道是否使用 esc_url()这里有道理。函数get_template_directory_uri()有自己的一小部分来清理 URL:

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

来源:get_template_directory_uri()

<小时/>

在起始主题中_s来自Automatic (wordpress 背后的公司),他们使用 get_template_directory_uri()直接无esc_url() .

看这里:functions.php

<小时/>

我的建议:

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

关于wordpress - 检索模板目录 : bloginfo ('template_url' ) or echo esc_url( get_template_directory_uri() )? 的 URL 的更好方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40529298/

相关文章:

wordpress Visual Composer 减慢网站速度

php - 如何在 Wordpress 中启用邮件?

php - 箭头键更改全屏背景图像

php - 如何从作者 ID 获取 WordPress 帖子总数?

html - 将自定义 css 添加到默认 style.css(Underscores _S Wordpress 主题)?

javascript - 输入意外结束

javascript - 您已在此页面上多次包含 Google Maps API

css - 更改 WooCommerce 单品中的自定义折扣价格百分比样式

php - WordPress - 在子类别 slug 上显示自定义分类法父类别

jquery - WordPress jQuery 未捕获类型错误 : Property '$' of object [object Object] is not a function