gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 01:28:56 24 4
gpt4 key购买 nike

使用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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com