问题描述
在自学wordpress官方主题开发手册中
此 page 显示了如何创建标题并使用了两个不同的函数:
两者都返回一个字符串,即图片网址。
这只是另一个令人困惑的冗余吗?或者两者之间是否存在实际差异。
解决方法
语义
显示·播放
在容易看到的地方为(某物)做一个显眼的展览。
这座宫殿曾经展示过一系列佛兰德挂毯。
重新·检索
得到或带回(某物);重新拥有。
我被派去他花园里取球
如何
虽然 header_image()
会回显标题图片网址,但 get_header_image()
不会。
<?php
header_image();
get_header_image();
header_image()
是 get_header_image()
的包装器。主要用在前端,作用是转义,回显get_header_image()。
<?php
/**
* Displays header image URL.
*
* @link https://developer.wordpress.org/reference/functions/header_image/
*/
function header_image() {
$image = get_header_image();
if ( $image ) {
echo esc_url( $image );
}
}
get_header_image()
的一个实际用例是在函数内部。
WordPress 将 get_ ...
的区别用于大多数默认功能,例如:
-
get_the_title()
和the_title()
。 -
get_the_post_thumbnail()
和the_post_thumbnail()
。 -
get_the_content()
和the_content()
。 ...等
我找到了答案。
有人发了然后很快就删了,只是为了让大家都在找答案:OnDeserialization
将在不需要使用 php SecondType
的情况下回显 URL。虽然 OnDeserialization
也会返回图像 URL,但它不会回应它。您必须为它使用 php echo。
注意:官方文档中没有提到这一点,除非我瞎了眼,否则我会挑战任何人向我展示官方页面中 echo 的位置,或者解释了这种区别的位置。