既存のテーマなどを使用しつつオリジナルにカスタマイズしたい場合は子テーマを作成しましょう。
子テーマは親テーマのスタイルシート以外の機能やテンプレートファイルを引き継ぐことができます。
子テーマを作成するメリットは様々ありますが、親テーマが更新されても上書きされないというメリットがあります。
子テーマの作成方法
1 themes内に任意のディレクトリを作成
(例としてwisebright-childを作成しました)
2style.cssを作成
3style.css内のコメントに以下を記述
Them Name: 子テーマの名前
Template: 親テーマの名前
4 functions.phpを作成
function.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’));}
?>
コメント