今回は子テーマがないテーマに子テーマを追加してみるということをやってみました。
親テーマに選定したのはTwenty Twenty-Five。やり方はググって、調べました。手順を簡単にまとめると、①PCのローカルに子テーマ用のフォルダを作成②functions.phpとstyle.cssを準備②-1 functions.phpの中身はお決まり(らしい)②-2 style.cssの中身は親テーマによって変えるところがある③準備できたら、フォルダごとzipで圧縮④WordPressの管理画面で読み込んで有効化
これだけ。
functions.phpの中身
1 2 3 4 5 6 7 8 |
<?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') ); } ?> |
つまづいたのは、style.cssです。
style.cssの中身↓
1 2 3 4 5 |
/* Theme Name: Twenty Twenty-Five Child Version: 1.2 Template: twentytwentyfive */ |
なにがつまづいたのかというと、親テーマの名前です。twentytwentyfiveはどこから取ってきたのかというと親テーマのフォルダ名。ここがなかなか気づけなかった。一度分かれば大したことないですが。
コメント