Welcome to Praful Bhuskute Black Spy Praful Bhuskute Black Spy Praful Bhuskute Black Spy

Create Child Themes in WordPress

A child theme allows you to change small aspects of your site’s appearance yet still preserve your theme’s look and functionality.

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?

A child theme inherits the look and feel of the parent theme and all of its functions, but can be used to make modifications to any part of the theme. In this way, customizations are kept separate from the parent theme’s files. Using a child theme lets you upgrade the parent theme without affecting the customizations you’ve made to your site.

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

Create Child Themes in WordPress

Step 3: Enqueue stylesheet in our child theme

This step is to enqueue the parent and child theme stylesheets

If the parent theme loads its style using a function starting with get_stylesheet, such as get_stylesheet_directory() and get_stylesheet_directory_uri(), the child theme needs to load both parent and child stylesheets. Be sure to use the same handle name as the parent does for the parent styles.
				
					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

now active child theme in wordpress

Drop your queries

Table of Contents

Have A Project In Mind? Let's Get To Work