HomeWordpress

How to Create a Child Theme in WordPress

How to Create a Child Theme in WordPress
Like Tweet Pin it Share Share Email

[myad1] Many WordPress developers are using WordPress Child Theme. The main purpose of a child theme is to extend the design and development and save the customization even parent themes are updated. As per the Client requirement or the website requirement, we need to do few customizations in the theme. It may be the pages modifications or CSS changes.

If you made the changes in the parent theme and after sometime updated are available for the customized theme. If someone has an update it then your all the changes will be gone. So to avoid this situation, you need to create a WordPress Child Theme.

A child theme required Parent theme and at least two files i.e function.php and style.css

  • Copy the parent theme’s folder and paste in the new folder anywhere or just copy paste in the same directory.
  • Now, you need to give Good Name to your Child theme. Rename it and add  “-child” word. If e.g parent theme is unityblogger then the child theme will be unityblogger-child.
  • If you want to use any other name then you can use.
  • Create a new function.php file and add below code.
<?php 
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' ); 
function my_theme_enqueue_styles() { 
  wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
?>
  • This code is used to initialize the Js and CSS in  WordPress using Hooks.
  • Above code will initialize the style CSS.
  • Create a new style.css file. In the style.css file, you need to add Theme Name and Parent theme’s name with Template. Copy below code and paste in the style.css file. Replace the content as per your requirement.
  • Suppose you want to create a child theme from twentysixteen theme then add below code in the style.css.
/* Theme Name: twentysixteen child
Template: twentysixteen*/
  • Save all the files.
  • Go to wp-admin and then theme section. You will see  “twentysixteen child” theme in the theme listing.
  • Please activate it and enjoy the WordPress Child Theme Customization.

Thanks for reading our article. What Next?

Comments (2)

Leave a Reply

Your email address will not be published. Required fields are marked *

3 × four =