2
2

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 2019-07-19

はじめに

Wordpressの子テーマを作る方法をまとめます。

なぜ子テーマをつくるのか

  • WordpressでテーマのCSSやPHPをガシガシいじりたい。

  • 親テーマのアップデートしたときに、自分のカスタマイズが上書きされないようにしたい。

子テーマディレクトリを作成する。

/wp-content/themesにフォルダを作成します。フォルダー名はなんでもいいです。

スクリーンショット 2019-07-19 11.58.03.png

style.cssを作成する

子テーマ内にstyle.cssファイルを作成します。
以下の内容を記述します。

/*
Theme Name:twentyseventeen-child
Theme URI:空欄でいい
Description:空欄でいい
Template:twentyseventeen
Author:空欄でいい
Author URI:空欄でいい
Version:2.2
*/
  • Theme Name: 子テーマの名前です。自分で名付けます。

  • Template: 親テンプレートの名前です。間違えないよう気をつけます。

  • Version: 親テンプレートのバージョンを書いておきます。

functions.phpを作成する

子テーマ内にfunctions.phpファイルを作成します。
以下の内容を記述します。

<?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
  wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
  wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array('parent-style')
);
}
?>

Wordpressで確認する

ダッシュボードからテーマ変更画面を開き、子テーマが認識されているか確認します。

スクリーンショット 2019-07-19 12.06.06.png

CSSを適当にいじってみて、動作確認もしてみましょう。

まとめ

Wordpressの子テーマを作る方法をまとめました。

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?