How to Create WordPress Child Theme without Plugin
In this article we will learn how to create child theme in wordpress without using any plugin. It will be very simple just follow the steps mentioned in this article.
What is Child Theme?
WordPress child themes are an essential tool for customizing the look and functionality of your website. A child theme is a theme that inherits the functionality and styling of another theme, called the parent theme. By using a child theme, you can make modifications to your site without losing the ability to update the parent theme.
Why should use child theme?
One of the main advantages of using a child theme is that it allows you to safely make customizations to your site without affecting the parent theme. This means that if the parent theme is updated, your customizations will not be lost or overwritten. This is particularly useful for sites that use a lot of custom code or have a lot of customizations, as it allows you to make updates without having to redo all of your work.
Using a child theme can also be useful when you’re building a website for a client, as it allows you to make customizations without affecting the parent theme, which can cause issues when the client wants to update the parent theme.
Other articles:
Encode Email Address to prevent Spam in WordPress.
Allow SVG File Upload in WordPress.
What you will need to create child theme?
Basically we need three files to create a wordpress child theme.
- Functions.php
- Style.css
- Screenshot (optional)
Functions.php – The functions.php file is used to add custom functionality to your child theme. This can include anything from adding new widgets to your site, to customizing the way that your site behaves. For example, you might want to add a custom post type, or create a new shortcode. To do this, you would add the relevant code to your child theme’s functions.php file.
Style.css – The stylesheet for a child theme is typically used to override any styles from the parent theme that you want to change. For example, you might want to change the background color of your site, or the font that is used for your headings. To do this, you would copy the relevant CSS from the parent theme’s stylesheet, and then make your changes. The new stylesheet will then be used instead of the parent theme’s stylesheet, allowing you to make your customizations.
Screenshot – It is the main image of your child theme. You can use your main theme’s screenshot also.
Video tutorial for how to create child theme in WordPress.
Steps to create Child theme
1) Create Folder.
Create a folder in your computer like you create normal folders. Rename the folder as main theme name. For example here i am creating child theme of astra theme, so i will rename the folder as astra-child.
2) Create necessary files.
a) Create functions.php
To create Functions.php file, right click anywhere on the screen and create a text document file. To do this, select New>Text Document, Just like the below image.
After creating the Text Document file, rename it to functions.php (make sure that the file extension name should be .php and not .txt) If you have not enabled file extension type, then enable it by going to your folder options and unceck the option “Hide extensions for known file type“.
b) Create Style.css
Now create the style.css file, just like you created the functions.php file, create a Text Document file and rename it to style.css.
c) Screenshot
You can select any jpg image file with the resolution of 1200px by 900px. Make sure to rename the image file to screenshot.jpg.
Once you created all three files, the folder will be look like the below image.
3) Edit the files.
Now we need to add codes in the files functions.php and style.css.
a) Edit Functions.php file.
Open functions.php file and add below code and then save it.
<?php
add_action( 'wp_enqueue_scripts', 'hubspot_blog_theme_enqueue_styles' );
function hubspot_blog_theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
However, if this code isn’t working for you, may be your theme might be coded differently, or it might not be following WordPress code conventions. In this case, please contact your theme author.
b) Edit Style.css file.
Open style.css file and add the below code.
/*
Theme Name: astra-child
Theme URI: http://wpamit.com/
Description: Astra is fast, fully customizable & beautiful theme.
Author: wpamit
Author URI: http://wpamit.com/
Template: astra
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/license/gpl-2.0.html
Tags: two-column, responsive-layout
*/
Here you need to make some necessary changes before saving it. First, change the Theme Name with name of child theme. Second, change the template name with your main theme template name. After making the changes, save the file.
4) Create zip folder.
Now, you need to zip the folder which we had created, like astra-child. You can use winrar to zip the folder or use the windows default option.
5) Upload the child theme.
Upload this zip folder as you upload the other themes. Once you uploaded your child theme, you can activate it in the same way that you would activate any other theme. This can be done by going to Appearance > Themes in the WordPress dashboard, and then selecting your child theme from the list of available themes.
In conclusion, WordPress child themes are a powerful tool for customizing the look and functionality of your site. By using a child theme, you can make modifications to your site without losing the ability to update the parent theme, and you can safely add custom code and customizations to your site without affecting the parent theme. Child themes are easy to create, and can be activated in the same way as any other theme. They are a great way to ensure your customizations are kept during parent theme updates, and also a great way to build and customize client sites.