How to Create a Child Theme in WordPress

0
136

Child themes let you customize your theme without disturbing the theme’s core files. When it’s time for updates to the theme, you can still upgrade it without losing your changes. Of course, you’ll want to make sure the theme still works after an upgrade and then see if the files you have updated also need changes to the code.

Here are the basic steps:

  1. Create a new folder, next to the current theme.
    • In this example, it’s a child of the twentyseventeen theme, so we’re calling it “twentyseventeen-child” and that is what the folder name needs to be.
  2. Add a style.css file (using the code below).
  3. Add a functions.php file (using the code below).
  4. Tell WordPress to start using the child theme.
  5. Copy whatever files you want to modify into the child theme folder.

For the style.css file, use this code:

/*
Theme Name: Twenty Seventeen Child
Theme URL: http://yourdomain.com
Description: Twenty Seventeen Child
Theme Author: Your Name
Author URL: http://yourdomain.com
Template: twentyseventeen
Version: 1.0.0
Text Domain: twentyseventeen-child
*/

Note the “Template” must be the name of the folder of the parent theme.

For the functions.php file, use this code:

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

Source: How to Create and Customize a WordPress Child Theme (hostinger.com)

LEAVE A REPLY

Please enter your comment!
Please enter your name here