What is a Parent Theme?
A parent theme is a complete theme that includes all of the required WordPress template files and assets for the theme to work.Â
What is a Child Theme?
Benefits of the child theme
- It allows you to make your modifications portable and replicable of the parent theme
- Keep customization separate from parent theme functions;
- Allow parent themes to be updated without destroying your modifications;
How to Create a Child Theme
Step 1: Create a child theme folder in wp-content/themes/
create a new folder in your themes directory, located at wp-content/themes.
The directory needs a name. It’s best practice to give a child theme the same name as the parent, but with -child appended to the end.
In this case, my parent’s name is Palmeria, then the directory would be named palmeria-child. refer image
Step 2: Create a stylesheet: style.css in wp-content/themes/palmeria-child/ location
Now we need to create a stylesheet file named style.css, which will contain all of the CSS rules and declarations that control the look of your theme. Your stylesheet must contain the below required header comment at the very top of the file. This tells WordPress basic info about the theme, including the fact that it is a child theme with a particular parent.
/*!
Theme Name: Palmeria child
Theme URI: https://themes.getmotopress.com/palmeria/
Author: MotoPress
Author URI: https://motopress.com
Template: palmeria
Description: Palmeria is a free WordPress Booking theme.
Version: 1.2.4
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
The following information is required:
- Theme Name – needs to be unique to your theme we use Palmeria child
- Template – the name of the parent theme directory. The parent theme in our example is the Palmeria theme. we use palmeria
Â
Ref this image
Step 3: Enqueue stylesheet in our child theme
This step is to enqueue the parent and child theme stylesheets
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
$parenthandle = 'parent-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.
$theme = wp_get_theme();
wp_enqueue_style( $parenthandle, get_template_directory_uri() . '/style.css',
array(), // if the parent theme code has a dependency, copy it to here
$theme->parent()->get('Version')
);
wp_enqueue_style( 'child-style', get_stylesheet_uri(),
array( $parenthandle ),
$theme->get('Version') // this only works if you have Version in the style header
);
}
Now Check the website Backend now you find a child theme, now active child theme
you can see the child theme now active child theme make sure parent theme is available in themeÂ
Note: Do not delete Parent Theme