get_header

函式
get_header ( $name = null, $args = array() )
引數
  • (string) $name The name of the specialised header.
    Required:
    Default: null
  • (array) $args Optional. Additional arguments passed to the header template. Default empty array.
    Required:
    Default: array()
返回值
  • (void|false) Void on success, false if the template does not exist.
定義位置
相關方法
get_header_imageget_custom_headerget_themelogin_headerget_the_date
引入
1.5.0
棄用
-

get_header: 這個函式用來檢索當前WordPress主題的標題模板檔案。頭部模板檔案通常用於顯示網站的標誌、導航選單或任何其他應該出現在每個頁面頂部的內容。

載入標題模板。

包括一個主題的標題模板,如果指定了一個名稱,那麼將包括一個專門的標題。

對於引數,如果檔案被稱為”header-special.php”,那麼指定”special”。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function get_header( $name = null, $args = array() ) {
/**
* Fires before the header template file is loaded.
*
* @since 2.1.0
* @since 2.8.0 The `$name` parameter was added.
* @since 5.5.0 The `$args` parameter was added.
*
* @param string|null $name Name of the specific header file to use. Null for the default header.
* @param array $args Additional arguments passed to the header template.
*/
do_action( 'get_header', $name, $args );
$templates = array();
$name = (string) $name;
if ( '' !== $name ) {
$templates[] = "header-{$name}.php";
}
$templates[] = 'header.php';
if ( ! locate_template( $templates, true, true, $args ) ) {
return false;
}
}
function get_header( $name = null, $args = array() ) { /** * Fires before the header template file is loaded. * * @since 2.1.0 * @since 2.8.0 The `$name` parameter was added. * @since 5.5.0 The `$args` parameter was added. * * @param string|null $name Name of the specific header file to use. Null for the default header. * @param array $args Additional arguments passed to the header template. */ do_action( 'get_header', $name, $args ); $templates = array(); $name = (string) $name; if ( '' !== $name ) { $templates[] = "header-{$name}.php"; } $templates[] = 'header.php'; if ( ! locate_template( $templates, true, true, $args ) ) { return false; } }
function get_header( $name = null, $args = array() ) {
	/**
	 * Fires before the header template file is loaded.
	 *
	 * @since 2.1.0
	 * @since 2.8.0 The `$name` parameter was added.
	 * @since 5.5.0 The `$args` parameter was added.
	 *
	 * @param string|null $name Name of the specific header file to use. Null for the default header.
	 * @param array       $args Additional arguments passed to the header template.
	 */
	do_action( 'get_header', $name, $args );

	$templates = array();
	$name      = (string) $name;
	if ( '' !== $name ) {
		$templates[] = "header-{$name}.php";
	}

	$templates[] = 'header.php';

	if ( ! locate_template( $templates, true, true, $args ) ) {
		return false;
	}
}

常見問題

FAQs
檢視更多 >