コトバノウタカタ

よしなしごとをつらつらとつづるばしょ。

Wordpressのchild css

バージョンやらサービスによって違うようなので。シンサーバー版覚書。

ファイルの準備

1. 自分のPCでファイルを置くフォルダを作る
2. 「style.css」というファイルを作り以下を書き込む

/*
Theme Name: Twenty Twenty-Five Child
Version: 1.0
Template: twentytwentyfive
*/

このとき、Theme Nameは新しいテーマの名前、Templateは現在使っているテンプレート名。「Twenty Twenty-Five」なら「twentytwentyfive」にする。

続けてcssを書く。

3. 「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')
);
}
?>

これはそのままコピペ。

4. フォルダをzip圧縮

zipをアップ

1. 管理画面から「外観」>「テーマ」を選択
2. 上の「テーマを追加」をクリックし、「テーマをアップロード」をクリック
3. 「ファイルを選択」が出るのでクリックしてzipファイルを選択
4. 「今すぐインストール」をクリック
5. 上書きだと「アップロードしたものでインストール済みのものを置き換える」をクリック
6. 「有効化」をクリック