get_header_image

函式
get_header_image ( No parameters )
返回值
  • (string|false)
定義位置
相關方法
get_header_image_tagheader_imageget_random_header_imagehas_header_imagethe_header_image_tag
引入
2.1.0
棄用
-

get_header_image: 這個函式用來檢索當前WordPress網站的頭像URL。頭部影象通常顯示在網站的主頁上。

檢索自定義頁首的頁首圖片。

function get_header_image() {
	$url = get_theme_mod( 'header_image', get_theme_support( 'custom-header', 'default-image' ) );

	if ( 'remove-header' === $url ) {
		return false;
	}

	if ( is_random_header_image() ) {
		$url = get_random_header_image();
	}

	/**
	 * Filters the header image URL.
	 *
	 * @since 6.1.0
	 *
	 * @param string $url Header image URL.
	 */
	$url = apply_filters( 'get_header_image', $url );

	if ( ! is_string( $url ) ) {
		return false;
	}

	$url = trim( $url );
	return sanitize_url( set_url_scheme( $url ) );
}

常見問題

FAQs
檢視更多 >