Creativemotions»WordPress Tips & Guides»WordPress Child Themes: What They Are and How to Create Them
wordpress child theme
Once you have chosen a suitable theme for your website, you may need to make minor changes, exposing you to risks and problems, not least of which is the risk of losing your changes when the theme is updated.
By creating a WordPress child theme , it will inherit the functionality and style of the parent theme making the editing process easy and safe.
In this post, we will list the potential dangers of modifying overseas chinese in usa data themes, talk about the benefits of WordPress child themes , and how you can create them yourself (manually or with a plugin).
Let's get started!
Table of Contents view
Changes to your theme: Don’t do them without a WP Child Theme!
Editing your WordPress theme can be a nerve-wracking experience. Even a small mistake on your part can cause hours of stress and work to fix the errors. Plus, any changes you make to the theme will be lost as updates are released.
You then have to make the difficult decision to either stay with your current version and risk security vulnerabilities , or update your theme and lose all your hard work (or, if you want, make all your changes again with every new theme update!)
WordPress child themes are the solution to these problems, as any changes you make are preserved regardless of what happens to the main theme (or parent theme).
The Benefits of Using Child Themes for WordPress
WordPress child themes have several advantages: first of all, they allow you to directly customize your website without necessarily worrying about templates or many lines of code; furthermore, they are incredibly flexible as they allow you to extend the functionality of the site and the changes made can be easily accessed and modified at any time.
Disadvantages of Using Child Themes for WordPress
Of course, no solution is perfect and to use a child theme effectively, you need to thoroughly familiarize yourself with the various functions and hooks of the parent theme.
Depending on the characteristics of your main theme, this may require a large investment of time.
How to create a WP child theme
Anyone can create their own WordPress child theme. If you choose the manual route, there are three main steps you will need to follow:
Create a new folder in wp-content/themes .
Create a dedicated Cascading StyleSheet (CSS) file.
Create a functions.php file .
To complete the above steps, you need to use a File Transfer Protocol (FTP) client such as FileZilla .
You can find the information you need (such as host, username and password) on your host's backend.
Once connected, locate your website's root folder (usually called public_html , www , or whatever your website name is) and go to wp-content > themes. Right-click in the box, create a new folder, and name it after your parent theme, adding –child.
This designates it as a WordPress child theme:
filezilla
Open the new directory, right-click and select Create New File. Name the file style.css – this will be the stylesheet for your child theme. Of course, it’s not a real stylesheet until you add CSS code.
Simply copy and paste the following code into your new file (changing the example text to match your theme) and save your changes:
/*
Theme Name: twentyseventeenchildtheme
Theme URI: https://wordpress.org/themes/twentyseventeen/
Description: Twenty Seventeen Child Theme
Author: John Doe
Template: twentyseventeen
Version: 1.0
*/
Next, you will need to make sure that the WP child theme can access the current styling of the parent theme.
To do this, follow the same steps as above, but this time name the file functions.php and add these lines of code:
<?phph
add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
function enqueue_parent_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}
This allows the parent theme's stylesheet to be loaded whenever the child theme is used.
Finally, go to Appearance > Themes in WordPress , locate the WordPress child theme you just created, and activate it. Your site's child theme should now be the primary option.
WP child Theme vs. Custom CSS
At some point, you may find yourself wanting to make small stylistic changes to your website. The question then becomes: should you update your child theme's stylesheet or insert custom CSS?
Simply put, custom CSS is an area within the WordPress Theme Customizer (and other third-party plugins) that allows you to add CSS that overrides your theme’s default styling options.
WordPress Child Themes: What They Are and How to Create Them
-
- Posts: 1194
- Joined: Tue Dec 24, 2024 4:28 am