A child theme allows you to extend the styles and functionality of a WordPress theme without losing them with every update of the parent theme.
-
Create a directory inside
wp-content/themeswith the same name as the parent theme and the suffix-child. For example:twentytwenty-child. -
Create a
style.cssfile with the code:/* Theme Name: Twenty Twenty Child Template: twentytwenty */The only required fields are Theme Name and Template, where Template is the name of the parent theme’s directory.
-
If you want to load the parent theme’s stylesheet as well (most likely yes), you must also add a
functions.phpfile in the same directory with the code:<?php /* enqueue script for parent theme stylesheet */ function childtheme_parent_styles() { // enqueue style wp_enqueue_style( 'parent', get_template_directory_uri().'/style.css' ); } add_action( 'wp_enqueue_scripts', 'childtheme_parent_styles');
Finally, you can activate the theme from the Appearance section of the WordPress dashboard.