[英]Wordpress site_url embedded in header_image() return value
[英]what is the difference between get_header_image() and header_image() in wordpress
在自学过程中从官方wordpress主题开发手册
此页面显示了如何创建标题并使用了两个不同的功能:
两者都返回一个字符串,即图像 URL。
这只是另一个令人困惑的冗余吗? 或者两者之间是否存在实际差异。
在容易看到的地方突出展示(某物)。
宫殿曾经展示一系列佛兰芒挂毯。
拿回或带回(某物); 重新拥有。
我被派去从他的花园里取回球
虽然header_image()
将回显 header 图像 URL,但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()
的一个实际用例是在 function 中。
WordPress 使用get_...
来区分它的大多数默认功能,例如:
get_the_title()
和the_title()
。get_the_post_thumbnail()
和the_post_thumbnail()
。get_the_content()
和the_content()
。 ... ETC。我找到了答案。
有人发了然后很快删了,不过只是为了让所有正在寻找答案的人受益:
header_image()
将回显 URL 而无需使用 php echo
。 虽然get_header_image()
也会返回图像 URL 但它不会回显它。 您必须使用 php回声。
注意:官方文档中没有提到这一点,除非我是盲人,否则我挑战任何人向我展示它在官方页面中的echo位置,或者解释了这种区别的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.