How to Create and Use a Child Theme On Wordpress(Tutorial).

in #utopian-io7 years ago (edited)

image.png

What is Child Theme In WordPress:

We can consider Child theme as a mirror reflection of a theme. And that original theme becomes parent theme after creating a child theme for it. If we make any changes in parent theme it will also affect your child theme. But when you make changes to child theme it won't affect actual code of parent theme.This way we can customize our WordPress website according to our need without touching the original theme file.

image.png
Image source

Why Creating and Working on Child theme is so important?

Almost everybody wants to customize their WordPress website according to their need. A study from Elegant Themes suggests that above 85% user customize their WordPress theme. But very few of them use the child theme.

It's not wrong to customize your original theme, but later problem can arise when you want to upgrade your theme to the newer version because all the changes made before will be lost after updating the theme.
To avoid this problem it is necessary to create and work on a child theme, your works are always preserved on the child theme.
The child theme can save lots of development time as well since we can use already existed development and customize things according to our need.

How to Create Child Theme?

Please note that I am running WordPress on localhost using Xampp. You can directly perform these actions on your server if you are familiar with these things.However, I prefer customizing on localhost. If you don't know how to install WordPress on your PC please refer my previous tutorial here

Create a new folder for child theme inside theme directory.

Goto the WordPress theme folder of your project and create a new theme folder and give a suitable name.

I have named it testchild as you can see in above screenshot.
Remember not to use spaces in the name.


Create a new style.css file.

Create a new blank text file inside that folder and name it style.css as shown in the figure below.

Open the style.css file in your favourite editor and add following code there.

I am using WordPress's default twentyseventeentheme as an example in this tutorial.

/*
 Theme Name:   Test Child
 Theme URI:    http://example.com/Test-child
 Description:  Twenty Seventeen Child Theme
 Template:     twentyseventeen
 Version:      1.0
 License URI:  http://www.gnu.org/licenses/gpl-2.0.html
*/
 
/*  Theme customization goes here
------------------------------------------------------- */

Give your theme a appropriate name in Theme Name section and include the parent theme you are using in Template section. Make sure to write the exact parent theme name in this template section, this way wordpress will automatically take your theme as Child theme of its parent.

Save the style.css file.

Remember you can do all the customization from here adding your own CSS code.

Importing the Parent Theme Stylesheet.

Now in the final step, we need to enqueue the parent and child theme stylesheets. For this purpose we have to create a function.php file in our child theme and add wp_enqueue_scripts action and use wp_enqueue_style().

Again create a blank text file and name it function.php. Open it in your favourite text editor and the following code 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' );
}

And Save the File.

Congratulations!! you have just successfully created a child theme for WordPress.

Your Child Theme is ready. Now login to your WordPress admin panel and activate the child theme.



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Your post has caught my attention and has been resteemed to my 2800 followers

Power Resteem Service - The powerhouse for free resteems, paid resteems, random resteems

Congratulations! This post has been upvoted from the communal account, @minnowsupport, by asis from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, someguy123, neoxian, followbtcnews/crimsonclad, and netuoso. The goal is to help Steemit grow by supporting Minnows and creating a social network. Please find us in the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.

If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP. Be sure to leave at least 50SP undelegated on your account.

Hi! I picked one of your images that you submitted to 7 World's Continents Photo Challenge for today's yellow color challenge. Feel free to interact with the post below and answer some congratulation notes for your amazing pic! Thank you for your support and have a great day. Tomas

ColorChallenge - Green Thursday - @katteasis in 7 World's Continents Photo Challenge!

Thanks a lot..:)

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @katteasis I am @utopian-io. I have just upvoted you!

Achievements

  • You are generating more rewards than average for this category. Super!;)
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.15
TRX 0.12
JST 0.025
BTC 54441.42
ETH 2433.25
USDT 1.00
SBD 2.14