WordPress ·

WordPressテーマの編集

WordPressのテーマを変更する際に、元のテーマには手を加えず、バックアップ(子テーマとして表現)したファイルを編集して使用する方法です。

  1. 使用する子テーマを簡単に確認できるよう、テーマ名を組み合わせて「wp-content/themes」フォルダーに新しいフォルダーを作成します。(例:元のテーマが「twentyfifteen」の場合、「twentyfifteen-child」というフォルダーを作成)
  2. 元のテーマの「style.css」を子テーマのフォルダーにコピーし、「Theme Name」と「Themplate」を以下のように変更します。
    /*
    Theme Name: Twenty Fifteen Child
    Theme URI: https://wordpress.org/themes/twentyfifteen/
    Template: twentyfifteen
    Author: the WordPress team
    Author URI: https://wordpress.org/
    Description: Our 2015 default theme is clean, blog-focused, and designed for clarity. Twenty Fifteen's simple, straightforward typography is readable on a wide variety of screen sizes, and suitable for multiple languages. We designed it using a mobile-first approach, meaning your content takes center-stage, regardless of whether your visitors arrive by smartphone, tablet, laptop, or desktop computer.
    Version: 1.5
    License: GNU General Public License v2 or later
    License URI: http://www.gnu.org/licenses/gpl-2.0.html
    Tags: black, blue, gray, pink, purple, white, yellow, dark, light, two-columns, left-sidebar, fixed-layout, responsive-layout, accessibility-ready, custom-background, custom-colors, custom-header, custom-menu, editor-style, featured-images, microformats, post-formats, rtl-language-support, sticky-post, threaded-comments, translation-ready
    Text Domain: twentyfifteenTemplate: twntyfifteen
    This theme, like WordPress, is licensed under the GPL.
    Use it to make something cool, have fun, and share what you've learned with others.
    */
  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' );
    }
    ?>
  4. 元のテーマの「screenshot.png」を子テーマのフォルダーにコピーします。
  5. 変更する元のテーマのファイルを子テーマのフォルダーにコピーし、編集して使用してください。

(参考:http://codex.wordpress.org/Child_Themes)

コメントを残す

メールアドレスが公開されることはありません。 ※ が付いている欄は必須項目です