get_header

Sponsored Link

現在のテーマディレクトリからheader.phpテンプレートファイルをインクルードします。もし、名前が特殊な場合は、特殊なヘッダーとして、header-special.phpがインクルードされるでしょう。
テーマにheader.phpファイルがない場合、ヘッダーはデフォルトテーマのwp-content/themes/default/header.phpからインクルードされるでしょう。

Sponsored Link

Includes the header.php template file from your current theme’s directory. if a name is specified then a specialised header header-special.php will be included. If the theme contains no header.php file then the header from the default theme wp-content/themes/default/header.php will be included.

<?php get_header( $name ); ?>

get_headerのパラメーター

$name

(string) (optional) header-name.phpを呼びます。

(string) (optional) Calls for header-name.php.

デフォルト:なし

Default: None

デフォルトではないヘッダーをインクルード

この例は、header-myheader.phpをインクルードするでしょう。

This example will include header-myheader.php

<?php
get_header('myheader'); 
?>

シンプルな404ページ

次のコードは、”HTTP 404:Not Found”エラーに対して簡単なテンプレート例です。(これは404.phpとしてテーマにインクルードすることができます)

The following code is a simple example of a template for an “HTTP 404: Not Found” error (which you could include in your Theme as 404.php).

<?php get_header(); ?>
<h2>Error 404 - Not Found</h2>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

マルチヘッダー

別のページに別のヘッダー。

Different header for different pages.

<?php
if ( is_home() ) :
  get_header('home');
elseif ( is_404() ) :
  get_header('404');
else :
  get_header();
endif;
?>

備考

*名前パラメーターはバージョン2.7から追加されました。

* The name parameter was added in Version 2.7.

変更ログ

Since: 1.5.0

ソースファイル

get_header()は、wp-includes/general-template.phpに位置しています。

get_header() is located in wp-includes/general-template.php.

関連テンプレートタグ

get_header, get_footer, get_sidebar, get_template_part, get_search_form, comments_template

Sponsored Link