WordPress child theme

  • W katalogo themes tworzymy folder o nazwie naszego motywu. Dobrą zalecaną praktyką jest nazwanie motywów potomnych nazwą motywu rodzica z końcówką „-child”.
  • Jedynym wymaganym plikiem w motywie potomnym jest plik styles.css z odpowiednią deklaracją w komentarzu na początku przykładowa deklaracja poniżej:
/*
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:  twentyfifteenchild
*/
  • z czego jedynie „Theme Name” oraz „Template” są wymagane.
  • W pliku functions.php nalerzy wciągnąć rodzicielski motyw za pomocą funkcji

add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );

function my_theme_enqueue_styles() {
    $parenthandle = 'twentyseventeen-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.
    $theme = wp_get_theme();
    wp_enqueue_style( $parenthandle, get_template_directory_uri() . '/style.css',
        array(),  // if the parent theme code has a dependency, copy it to here
        $theme->parent()->get('Version')
    );
    wp_enqueue_style( 'child-style', get_stylesheet_uri(),
        array( $parenthandle ),
        //$theme->get('Version') // this only works if you have Version in the style header
    );
}
  • W CMS’ie należy uruchomić pochodny styl

Dodaj komentarz