style.cssとfunctions.phpを設定してテーマとして認識させる


style.cssとfunctions.phpを設定してテーマとして認識させる

※これをする前にいくつかしないといけない事はある。

index.phpと同階層にあるテーマ認識用のstyle.cssに以下を記述。

style.css

@charset "utf-8";
/---------------------------------
テーマとしてWPに認識させるための記述↓
---------------------------------/
/*
theme Name:hoge
Author: hoge
Description: 自作テーマ
version: 1.0.0
*/

functions.php

<?php
/**
 * テーマのセットアップ
 * 参考:https://wpdocs.osdn.jp/%E9%96%A2%E6%95%B0%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9/add_theme_support#HTML5
 **/
function my_setup()
{
  add_theme_support('post-thumbnails'); // アイキャッチ画像を有効化
  add_theme_support('automatic-feed-links'); // 投稿とコメントのRSSフィードのリンクを有効化
  add_theme_support('title-tag'); // タイトルタグ自動生成
  add_theme_support(
    'html5',
    array( //HTML5でマークアップ
      'search-form',
      'comment-form',
      'comment-list',
      'gallery',
      'caption',
    )
  );
}

add_action('after_setup_theme', 'my_setup');
// セットアップの書き方の型
// function custom_theme_setup() {
// add_theme_support( $feature, $arguments );
// }
// add_action( 'after_setup_theme', 'custom_theme_setup' );

上記のコードを記述し、
WordPressのadminの管理画面で、「外観 > テーマ」で認識されている。