[英]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.