Child theme

26.07.2017

Создаем дочернюю тему.

первым делом создается папка с таким же именем как у родителя с добавлением суффикса -child, например, получится twentyfifteen-child.

Обязательным является один единственный файл style.css с примерным заголовком:

/*
 Theme Name:   Twenty Fifteen Child
 Theme URI:    http://example.com/twenty-fifteen-child/
 Description:  Twenty Fifteen Child Theme
 Author:       John Doe
 Author URI:   http://example.com
 Template:     twentyfifteen
 Version:      1.0.0
 License:      GNU General Public License v2 or later
 License URI:  http://www.gnu.org/licenses/gpl-2.0.html
 Tags:         light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
 Text Domain:  twenty-fifteen-child
*/

В файле функций functions.php подключаем родительский файл стилей:

<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
?>

Например, нужно подключить и дочерний и родительский файл style.css:

function child_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');
}
add_action( 'wp_enqueue_scripts', 'child_theme_enqueue_styles' );

Больше информации ищите в Кодексе.

Рекомендую к прочтению:

Оставить комментарий