Child themes saved your modifications from parent theme updates. If you want to change theme style, layout or something, you should use child theme.

Minimal structure of child theme

A child theme needs two files at least.

  1. style.css
  2. functions.php
  3. screenshots.png (optional)

Create a child theme one by one

1. Create a child theme folder in themes folder.
Give a same name as the parent with ‘-child’ appended to end. For example, if you were making a child theme of twentyseventeen, would be named twentyseventeen-child.

/http-docs/wp-content/themes/twentyseventeen         ==> Your parent (main) theme
/http-docs/wp-content/themes/twentyseventeen-child ==> Your child theme

2. Create a stylesheet in your child theme folder and named ‘style.css‘ and use the following code

/*
Theme Name: Twenty Seventeen Child
Theme URL: http://example.com/
Description: A child theme of Twenty Seventeen Theme
Author: John Doe
Author URL: http://example.com
Template: twentyseventeen
Version: 1.0.0
Text Domain: twentyseventeen-child
*/ 

Custom CSS goes after this line

3. Create a php file and named ‘function.php‘. Use the following code

<?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' );
}

4. Go to Appearance -> Themes and activate Child theme.

Resources

  1. https://www.wpbeginner.com/wp-themes/how-to-create-a-wordpress-child-theme-video
  2. https://developer.wordpress.org/themes/advanced-topics/child-themes/
Author

Write A Comment