0
1

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 3 years have passed since last update.

wordpressで子テーマをつくる

Last updated at Posted at 2021-06-06

やること

wordpressで子テーマをつくる際に必要な初期設定をまとめる

  • 親テーマと違うことをstyle.cssで宣言
  • functionに子テーマのstyleを読み込むように設定

子テーマを作る際の流れ

  • 子テーマは基本的には親テーマとの際の部分だけかくという形。親テーマは常にwordpress内にインストールしていないといけない
  • 子テーマにするメリットは親テーマが自動更新がかかってもその影響で勝手にファイルが消えたりしないこと
  • 下記は必須だがほかは必要ファイルのみ用意する
    • style.css
    • functions.php

参考資料
「初心者でも3分でわかる!WordPressの子テーマの作り方」
https://freesworder.net/wordpress-child-theme/

style.cssで子テーマと明記

style.css
/*
Theme Name:{子テーマの名前}
Template:{親テーマの名前}
*/

functionsの記述

functions.php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}

上記で親テーマのcssを読み込み、子テーマのcssも読み込むようになる

参考資料

その他注意

子テーマのimgの表示方法

<img src=<?php echo get_stylesheet_directory_uri(); ?>/images/sample.jpg />

各ページの役割

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?