0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

wordpressのテンプレートタグ・カスタムヘッダーの表示

Last updated at Posted at 2017-09-23

wordpress(企業サイト制作を前提)

テンプレートタグ

  • 有効にしているテーマのスタイルシートのパスを出力するタグ

    get_stylesheet_uri();

    ※ php bloginfo('stylesheet_url'); という記述もありますが、現在は非推奨。

【テンプレートタグ】

  1. サイト名称を出力
    php bloginfo('name');
  2. ヘッダーを読みこむ
    get_header();
  3. フッターを読み込む0
    get_footer();
  4. サイドバーを読み込む
    get_sidebar();

※上記の2 3 4 のタグは get_template_part();に置き換えできる。
 例:header.php ファイルを読み込むときは
   get_template_part('header');

  • header.php, footer.phpに追記必須のテンプレートタグ
     ⇒ メタタグの出力、Javascriptライブラリの読み込み、Wordpressのツールバーの表示させる

(header.phpファイル)
</head>の直前に下記を追加
<?php wp_head(); ?>

(footer.phpファイル)
<body/>の直前に下記を追加
<?php wp_footer(); ?>

  • トップページへリンクを出力

    <?php home_url('/'); ?>

カスタムヘッダーでメインイメージを表示させる

カスタムヘッダー機能を利用することで、トップページのメインイメージを管理画面で設定できるようになる。

  1. .../ themes / ※自作テンプレートフォルダ / functions.php を作成して、下記を記述する。
例:
//カスタムヘッダー
add_theme_support(
'custom-header',
      array(
		'width' => 950,
		'height' => 295,
		'header-text' => false,
		'default-image' => '%s/images/top/main_image.png',
       )
);
  1. 上記のファイルを追加することで、管理画面「外観」にて画像のアップロードができる状態になる。
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?