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
查看更多 >