TwentyFifteenを独自テンプレートにカスタマイズする方法

シンプルなWordPressのテンプレートを探していたところ、意外と「TwentyFifteen」が良さそうだったのでカスタマイズしてみました。

0. ファイル構成

TwentyFourteenに比べるとファイルも少なくなっているので良いですね。

ちゃんと見てないですが、style.css内のメディアクエリもブレークポイントが少なくなっているようでカスタマイズしやすそうです。

content*.phpといったファイルは、WordPressループなどを含むコンテンツの表示用のファイル。

また、inc/以下のファイルはfunctions.phpで読み込まれるカスタマイズ用のファイルです。

404.php404 テンプレート
archive.phpアーカイブ
author-bio.php著者情報
comments.php コメント
content-link.phpリンクポストフォーマット用
content-none.phpコンテンツがない時用
content-page.php固定ページ用
content-search.php検索結果
content.phpメインとなるコンテンツ表示
footer.php フッター
functions.phpテーマのための関数
header.php ヘッダー
image.php画像添付テンプレート
inc/back-compat.phpWordPress4.1未満用
inc/custom-header.phpカスタムヘッダー用
inc/customizer.phpテーマカスタマイザー
inc/template-tags.phpテンプレートタグ
index.phpメインインデックスのテンプレート
page.php 固定ページテンプレート
search.php 検索結果
sidebar.phpサイドバー
single.php 単一記事の投稿
style.cssスタイルシート
rtl.cssRTL スタイルシート

2. functions.phpから不要なコードを消す

WordPress4.1未満用の互換性確保のために back-compat.php を読み込む部分。 今回は不要なので削除。

/**
 * Twenty Fifteen only works in WordPress 4.1 or later.
 */
if ( version_compare( $GLOBALS['wp_version'], '4.1-alpha', '<' ) ) {
  require get_template_directory() . '/inc/back-compat.php';
}

twentyfifteen_setup()内の不要な設定を削除。

言語ファイルの設定。一部英語化してしまうけれど、あとで修正するので削除。

/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on twentyfifteen, use a find and replace
* to change 'twentyfifteen' to the name of your theme in all the template files
*/
load_theme_textdomain( 'twentyfifteen', get_template_directory() . '/languages' );

ポストフォーマットの登録。使わない人は削除。

/*
 * Enable support for Post Formats.
 *
 * See: https://codex.wordpress.org/Post_Formats
 */
add_theme_support( 'post-formats', array(
  'aside', 'image', 'video', 'quote', 'link', 'gallery', 'status', 'audio', 'chat'
) );

テーマを管理画面からカスタマイズする用(カスタムヘッダーなど)不要なので削除。

$color_scheme  = twentyfifteen_get_color_scheme();
$default_color = trim( $color_scheme[0], '#' );

// Setup the WordPress core custom background feature.
add_theme_support( 'custom-background', apply_filters( 'twentyfifteen_custom_background_args', array(
  'default-color'      => $default_color,
  'default-attachment' => 'fixed',
) ) );

custom-header.php、customizer.phpは不要なので削除。

/**
 * Implement the Custom Header feature.
 *
 * @since Twenty Fifteen 1.0
 */
require get_template_directory() . '/inc/custom-header.php';

/**
 * Customizer additions.
 *
 * @since Twenty Fifteen 1.0
 */
require get_template_directory() . '/inc/customizer.php';

3. 不要なファイルを消す

functions.phpを編集した後に、下記のファイルを削除。

rtl.css
back-compat.php
custom-header.php
customizer.php
content-link.php

4. カスタマイズ

To be Updated…

[amazonjs asin=“B00UR988KS” locale=“JP” title=“本格ビジネスサイトを作りながら学ぶ WordPressの教科書 Ver.4.x対応版”]