Child theme is a great option if you are using a theme downloaded from WordPress.org or another theme provider.
A child theme needs to have:
– their own theme folder in wp-content/themes
e.g. wp-content/themes/xxx-child
– style.css
file
– functions.php
file
style.css
/*
Theme Name: Child Name
Theme URI: http://example.com/my-child/
Description: Child Theme
Author: Jane Dow
Author URI: http://glorious-site.com
Template: parentFolderName
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: my-child
*/
functions.php
Note that functions.php
in child theme is loaded in addition to the parent’s functions.php
.
Enqueue both parent’s and child’s style.
<?php
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')
);
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
?>
More info on Codex – Child Themes