Whenever you face the need to make customizations directly to your website’s core files, especially to the functions.php
file ⚠️, it is recommended that you create a child theme for that purpose. Child themes can help isolate the code from the main site and preserve the changes you made even after a major WordPress upgrade.
Here’s a basic structure of a child theme:
child-theme-name/
├── style.css
└── functions.php
Create the style.css file:
/*
Theme Name: Child Theme Name
Theme URI: https://example.com/child-theme-name/
Description: Child theme for Parent Theme Name.
Author: Your Name
Author URI: https://example.com
Template: parent-theme-name // Replace with your parent theme's name
Version: 1.0.0
*/
/* Your custom CSS styles go here */
Create the functions.php file:
<?php
function child_theme_enqueue_styles() {
wp_enqueue_style( 'parent-theme-style',
get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-theme-style', get_stylesheet_directory_uri() . '/style.css', array(
'parent-theme-style' ) );
}
add_action( 'wp_enqueue_scripts', 'child_theme_enqueue_styles' );
Explore these videos for insights and tutorials on Child theme. This section comprises 3 modules with a combined duration of 25 minutes.
Video Content | Time |
---|---|
Basics of Child Themes | 06:14 |
Overriding Parent Functionality Pt 1 | 11:57 |
Overriding Parent Functionality Pt 2 | 06:57 |
For more information on WordPress child themes, check out the Child Themes page from the Theme Developer Handbook.