子テーマのざっくり作り方

1、~/wp-content/themes/の配下に入り、対象のテーマのDIR名を{DIR_name}⇒{DIR_name-child}の形式でmkdir、例えば


[root@hostname themes]# mkdir mytheme-child

2、子テーマの構成要素を洗い出し、それぞれを作る
①style.css ⇒スタイルシート、独自スタイルを適用するためのもの
②functions.php ⇒WPコアにここは子テーマであることを宣言し、認識してもらう

まずはstyle.cssの冒頭記述例


/*
 Theme Name:    Coldbox Child TERNS.tokyo ver
 Theme URI:     https://terns.tokyo/
 Description:   Just an another Coldbox child theme.
 Author:        Shinya
 Author URI:    https://terns.tokyo/
 Template:      coldbox 
 Version:       1.0.0
 License:       GNU General Public License v2.0
 License URI:   http://www.gnu.org/licenses/gpl-2.0.html
 Tags:          Customized
 Text Domain:   coldbox-child-tenrstokyo
*/

中でも特に重要なのは下記の二項目、記述漏れや入力ミスのないよう注意すること


 Theme Name:   {Your Child theme name}
 Template:     {Parent theme DIR name}

そして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') );
	}
?>

これで最低限の「Hello! Wolrd.」の準備は整えた。次はfunctions.phpにいろいろ追加してみることだ。

学爾時習之、不亦悦乎? 有朋自遠方来、不亦楽乎? 人不知爾不愠、不亦君子乎?

シェアする

コメントを残す

コメントする

CAPTCHAis initialing...