In this article, we will discuss how to create a child theme WordPress both without using a plugin and by using a plugin. You can certainly choose which method you find easier and more efficient.
By using a child theme WordPress, you can make theme changes, especially adding code to the functions.php file, without losing your changes when updating the theme.
What is a WordPress Child Theme?
Just as the name implies, a child theme, which roughly means a "Theme Derivative," is a theme created based on a parent theme or the main WordPress theme, so we can have more flexibility to manage and customize the theme.
How to Create a WordPress Child Theme Without a Plugin
There are several steps to create a WordPress child theme without using a plugin, including
- Creating a WordPress Child Theme Folder
- Adding a style.css File
- Adding functions.php
- Adding a Screenshot
1. Create a WordPress Child Theme Folder
The first step you need to take is to create a folder used to store the child theme files you will create.
For example, if you are going to create a child theme from Neve and the child theme name to be used is Neve-me, then you can create a folder neve-me inside the WordPress installation theme folder
2. Add a style.css File
Inside the child theme folder you have created, in this example neve-me, you can add a file named style.css, then add the following lines inside the style.css
/*Theme Name: Neve-meTheme URI: https://staging.wpgan.com/neve-meDescription: Child theme Neve dengan nama Neve-meAuthor: WPGanAuthor URI: http://wpgan.comTemplate: neveVersion: 1.0.0License: GNU General Public License v2 or laterLicense URI: http://www.gnu.org/licenses/gpl-2.0.htmlTags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-readyText Domain: nevemechildtheme*/file. From the style.css content above, make sure to change these two lines
- Theme Name: Contains the name of the child theme you created, which will later be displayed in the WordPress theme dashboard
- Template: Change this to the name of the theme folder you are using. For example, if you are creating a child theme for Twenty Twenty-Three, then you can change the template name to twentytwentythree
Now when you open the theme page from the WordPress dashboard, you can see the child theme you created, but some theme features might not be usable or may even cause errors because we have not created a functions file
3. Add functions.php
Next, you need to add a functions.php file to the child theme folder to ensure the theme can be used and so you can later add custom code to the functions.php file that will not be lost even when updating the main theme.
After the functions.php file is successfully created, fill the content inside with the following lines of code
<?phpadd_action( 'wp_enqueue_scripts', 'wpgan_enqueue_styles' );function wpgan_enqueue_styles() { wp_enqueue_style( 'child-style', get_stylesheet_uri(), array( 'parenthandle' ), wp_get_theme()->get( 'Version' ) // Ini hanya berfungsi jika kamu telah menentukan Versi di style header. );}In some cases, there are templates that use get_stylesheet, for example get_stylesheet_directory() and get_stylesheet_directory_uri(). If the theme you are using uses this stylesheet calling method, then you need to use the following code inside the functions.php file
<?phpadd_action( 'wp_enqueue_scripts', 'wpgan_enqueue_styles' );function wpgan_enqueue_styles() { $parenthandle = 'parent-style'; // Ini adalah 'twentyfifteen-style' untuk tema Twenty Fifteen. $theme = wp_get_theme(); wp_enqueue_style( $parenthandle, get_template_directory_uri() . '/style.css', array(), // Jika kode tema utama memiliki dependency, salin ke sini. $theme->parent()->get( 'Version' ) ); wp_enqueue_style( 'child-style', get_stylesheet_uri(), array( $parenthandle ), $theme->get( 'Version' ) // Ini hanya berfungsi jika kamu telah menentukan Versi di style header. );}4. Add a Screenshot
So that the theme menu in your WordPress dashboard has a main image, you can add a theme screenshot image with the filename screenshot.png. Make sure the filename and extension are the same
Now you can open the theme page in your WordPress dashboard, and the child theme is ready to be activated
Creating a WordPress Child Theme With a Plugin
There are many plugins you can use to create a child theme instantly, for example Child Theme Configurator, Child Theme Wizard, WP Child Theme Generator, Generate Child Theme, and so on.
Here we will use the Child Theme Configurator plugin because this plugin is the most commonly used plugin for creating child themes.
After the Child Theme Configurator plugin is installed in WordPress, you can then follow these steps to create a child theme, for example creating a child theme from GeneratePress.
Log in to the WordPress dashboard as an admin, then after you are inside the WordPress dashboard, you can open the Tools → Child Themes
menu. From the Child Theme page, you can select the CREATE a new Child Theme option and choose the main theme you will use, for example GeneratePress , then click the Analyze.
button. After the status is OK, you can continue the process by giving the child theme folder a name as you did in step number 4, for example Alternatif-GeneratePress. For option number 5, just leave it using the default option
For option number 6, you can choose how the stylesheet from the main theme is called. For this option, it is recommended to use the Use the WordPress style queue. option, and for the Advanced handling options option, you can just leave it as is.
To change child theme details such as the theme name, description, tags, and so on, you can click the Click to Edit Child Theme Attributesmenu, then change the child theme information. For example, changing the child theme name to Alternatif GeneratePress
Now everything is finished and you can create your first child theme using a plugin by clicking the Create New Child Theme
button. If successful, you will get the message "Child Theme Alternatif GeneratePress has been generated successfully. IMPORTANT: Preview your child theme before activating," and now you can open the Appearance page in the WordPress dashboard to check the child theme that has been successfully created.
Those are two easy ways to create a WordPress child theme, either using a plugin or without using a plugin. If you create a child theme using a plugin but get an error, you can try regenerating the child theme using the same plugin or try with another plugin.
COMMENTS
Loading...