[wordpress] How to create a child theme?

Follow the steps below:

1) Create a new folder inside the themes folder (wp-content/themes). You can give the name you want, however it’s a best practice to give the same name as the parent theme, followed by the -child suffix. So, if you want to create the Twenty Twenty child theme, you would have to create the folder twentytwenty-child like so: wp-content/themes/twentytwenty-child .

2) Create a stylesheet file inside the folder you just created. Give it the name style.css. This file must have these basic information on the top:

/*
 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
*/

The Theme Name and Template are required.
Add the remaining information accordingly.

3) Finally, you should create another file with the name functions.php with the purpose of enqueuing the child theme stylesheet.

<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
 
    $parent_style = 'parent-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.
 
    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style',
        get_stylesheet_directory_uri() . '/style.css',
        array( $parent_style ),
        wp_get_theme()->get('Version')
    );
}

Source:
https://developer.wordpress.org/themes/advanced-topics/child-themes/

Leave a comment

Your email address will not be published. Required fields are marked *