wp-content » themes » functions.php » How to Create a WordPress Child Theme

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.

How to create a WordPress Child 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:

child tema - How to Create a WordPress Child Theme

style.php

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
*/

functions.php

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.
See also  How to pick the best WordPress theme for your business in 2023

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

done child theme - How to Create a WordPress Child Theme

TIPS:

Because the functions.php file needs to contain PHP code, it should start with an opening PHP tag:

<?php

⚠️ Any custom functions can be placed below this, but ensure there are no extra <?php tags when you’ve pasted your snippet!


⚠️ If a WordPress plugin calls the same function or filter, as you do in your functions.php file, the results can be unexpected, even causing your site to be disabled.


WordPress Developer Handbook contains more info about theme functions.php files.

Was this post helpful?

Leave a Comment

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.

Recommended