<?php
function theme_enqueue_styles() {
//親テーマのCSSを読み込み
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
//親テーマのCSSを上書き
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array('parent-style'));
}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
?>
style.cssを用意する
子テーマのstyle.cssにも、親テーマのstyle.cssのように必要情報を冒頭に記載します。
/*
Theme Name:テーマの名前
Theme URI:テーマに関連するWebサイトのURL
Description:テーマの説明
Template:親テーマのディレクトリ名
Author:テーマ作成者の名前
Author URI:テーマ作成者のWebサイトのURL
Version:テーマのバージョン
*/
Theme Name | 「親テーマの名前 child」が一般的です。 |
Theme URI | ご自身のURLなど不要な場合は行ごと削除可 |
Description | 簡潔かつ明確にテーマの説明を記載します。 |
Template | 親テーマのディレクトリの名称を記載します。(親テーマのディレクトリ名が「twentytwenty」の場合は「twentytwenty」と記載します。) |
Author | 作成者名を記載します。 |
Author URI | 作成者のURLを記載します。 |
Version | 任意でバージョンを記載します。 |