get_header()
get_header( string $name = null )
加载头模板。
Load header template.
说明(Description)
包含主题的标题模板,或者如果指定了名称,则将包含专门的标题。
对于参数,如果文件名为“header-特殊.php然后指定“特殊”。
参数(Parameters)
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
$name | (string) | 可选 | 专门标题的名称。 |
返回(Return)
无返回值
源码(Source)
/** * Load header template. * * Includes the header template for a theme or if a name is specified then a * specialised header will be included. * * For the parameter, if the file is called "header-special.php" then specify * "special". * * @since 1.5.0 * * @param string $name The name of the specialised header. */ function get_header( $name = null ) { /** * Fires before the header template file is loaded. * * The hook allows a specific header template file to be used in place of the * default header template file. If your file is called header-new.php, * you would specify the filename in the hook as get_header( 'new' ). * * @since 2.1.0 * @since 2.8.0 $name parameter added. * * @param string $name Name of the specific header file to use. */ do_action( 'get_header', $name ); $templates = array(); $name = (string) $name; if ( '' !== $name ) $templates[] = "header-{$name}.php"; $templates[] = 'header.php'; // Backward compat code will be removed in a future release if ('' == locate_template($templates, true)) load_template( ABSPATH . WPINC . '/theme-compat/header.php'); }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
1.5.0 | wp-includes/general-template.php:22 | 0 | 3 |
笔记(Notes)
多个标题
命名头模板
简单404页
get_header() 为WP2原创文章,链接:https://www.wp2.cn/functions/get_header/