今回は、このブログで使用しているテーマ「arkhe」の子テーマを作成したので、その手順をまとめました!
※現在は「arkhe」ではなく「swell」を使っています。
目次
子テーマのフォルダを作成
まずは子テーマ用のフォルダをローカル環境に作成します。
![](https://mayuka.org/wp-content/uploads/2022/08/6bad8f00e2a2999a036215c64b1e0961.jpg)
フォルダ名はなんでもOKですが、「親テーマ名-child」などとすると、どのテーマの子テーマかわかりやすいです。
![](https://mayuka.org/wp-content/uploads/2022/08/79228a165a3dd6e01a521aad9e015a96.jpg)
style.cssの設定
作成したフォルダ内に「style.css」を作成します。
ファイルには以下を記述してください。
/*
Theme Name: Arkhe Child
Template: Arkhe
Description: Arkheの子テーマです。
Version: 1.0
*/
この中でも、
- Theme Name … 子テーマの名前(例:Arkhe Child)
- Template … 親テーマのフォルダ名(例:Arkhe)
以上の2つは必須です。
このとき、Templateで親テーマ名のスペルを間違えるとうまく認識されないので注意!
(私は最初スペルミスでうまく認識されなかった…。)
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'));
}
wp_enqueue_scriptsをフックにwp_enqueue_styleでstyle.cssを読み込んでいます。
子テーマを有効化する
最後に子テーマを有効化します。
ファイルを右クリックなどで圧縮します。
![](https://mayuka.org/wp-content/uploads/2022/08/689bf09509f34664d99ccec8a10c730f.jpg)
次に、WordPress管理画面の「外観>テーマ>新規追加」から先ほど圧縮したZIPファイルをアップロードしていきます。
![](https://mayuka.org/wp-content/uploads/2022/08/d2ddabd736f49d46de5a71c8fe80e331-1-1024x459.png)
子テーマが有効化されていれば完了です!
![](https://mayuka.org/wp-content/uploads/2022/08/28113e75d25f89e3c26f69404792961d-1024x509.png)
コメント