How to Create a WordPress Child Theme

60 seconds or less, that’s all that takes to create a WordPress child theme and I highly recommend that you do it before even thinking about making any code or style modifications to your active theme.

There are two files that you can use inside a child theme to overwrite parent theme’s functionality or style:

  • functions.php – to modify features, add new ones or remove them.
  • style.php – to overwrite css style of the theme.

To create a new child theme you don’t need any codding knowledge, but you do need to have access to the folder where your WordPress website is installed.

In this example I will use the TwentyTwenty theme , but you can use any theme that you want, just make sure to change twentytwenty in the examples bellow with your theme’s slug.

From your cPanel > File Manager navigate to the directory where WordPress is installed and then to /wp-content/themes

Inside this folder you can see all the themes that you have on the website, both active and inactive.

Create a new folder for your theme:


Inside this folder create two new files, first create a file style.css and add the following code inside it:

/*
 Theme Name:   Moja Prva Child Tema
 Theme URI:	https://wpxss.com/wp-content/themes/
 Description:  A Twenty Twenty child theme
 Author:        STEFAN
 Author URI:   https://wpxss.com/
 Template: 	twentytwenty
 Version:  	1.0.0
*/

Create a new file, name it functions.php and put the following inside:


<?php

add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
function enqueue_parent_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );

}

?>

This code does two things:

  1. Enqueue the parent and child themes’ stylesheets so that the child theme inherits all elements of the parent theme.
  2. Makes sure that the child theme’s stylesheet is loaded before the parent theme’s – without overriding it.

That’s it, now from wp-admin navigate to Appearance > Themes and you can activate the child theme.

Was this post helpful?

Leave a Comment