Create child theme in wordpress

WordPress Structure, Wordpress Tutorials

Create child theme in wordpress

child theme in wordpress

Why use a Child Theme In WordPress?

There are a few reasons why you would want to use a child theme in WordPress:

  • If you modify a theme directly and it is updated, then your modifications may be lost. By using a child theme you will ensure that your modifications are preserved.
  • Using a child theme can speed up development time.
  • Using a child theme is a great way to learn about WordPress theme development.

How to Create a Child Theme

A child theme consists of at least one directory (the child theme directory) and two files (style.css and functions.php), which you will need to create:

  • The child theme directory
  • style.css
  • functions.php

The first step in creating a child theme is to create the child theme directory, which will be placed in wp-content/themes. It is recommended that the name of your child theme directory is appended with ‘-child’. You will also want to make sure that there are no spaces in your child theme directory name, which may result in errors. In the screenshot above we have called our child theme ‘Helpyouforever-child’, indicating that the parent theme is the helpyouforever theme.

The next step is to create a style.css file that must start with some commenting code that comment contains the child theme information and that code looks like as below.

/*
 Theme Name:   Helpyouforever Child
 Theme URI:    http://www.helpyouforever.com/Helpyouforever-child/
 Description:  Helpyouforever Child Theme
 Author:       Mahesh and Gaurang
 Author URI:   http://www.Helpyouforever.com
 Template:     helpyouforever
 Version:      1.0.0
 License:      GNU General Public License v2 or later
 License URI:  http://www.gnu.org/licenses/gpl-2.0.html
 Text Domain:  helpyouforever-child
*/

The final step is to enqueue the parent and child theme stylesheets. The correct method of enqueuing the parent theme stylesheet is to add a wp_enqueue_scripts action in your child theme’s functions.php. You will, therefore, need to create a functions.php in your child theme directory. If your child theme has more than one .css file (eg. ie.css, style.css, main.css) then you will have to make sure to maintain all of the Parent Theme dependencies.

<?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );

}
?>

If your child theme style.css contains actual CSS code (as it normally does), you will need to enqueue it as well. Setting ‘parent-style’ as a dependency will ensure that the child theme stylesheet loads after it. Including the child theme, version number ensures that you can bust cache also for the child theme.

<?php
function theme_enqueue_styles() {

    $parent_style = 'parent-style'; // This is 'Helpyouforever-style' for the Helpyouforever theme.

    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style',
        get_stylesheet_directory_uri() . '/style.css',
        array( $parent_style ),
        wp_get_theme()->get('Version')
    );
}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
?>

 

Your child theme is now ready for activation. Log in to your site’s administration panel, and go to Administration Panels > Appearance> Themes. You should see your child theme listed and ready for activation. (If your WordPress installation is multi-site enabled, then you may need to switch to your network administration panel to enable the theme (within the Network Admin Themes Screen tab). You can then switch back to your site-specific WordPress administration panel to activate your child theme.)

That is all about the child theme in WordPress. If you still need confusion then you can comment on that post we will reply you and also can refer the http://wordpress.org official website.

6 thoughts on “Create child theme in wordpress

  1. A lot of thanks for all of your hard work on this website. My mother enjoys working on internet research and it’s simple to grasp why. Most people hear all concerning the dynamic tactic you render priceless tips and hints through this web site and in addition improve response from some others about this area of interest then our own princess is in fact discovering so much. Take pleasure in the remaining portion of the new year. You’re doing a stunning job.

  2. Hello would you mind letting me know which webhost you’re
    utilizing? I’ve loaded your blog in 3 comlletely different web browsders
    and I must say this blog loads a lot quicker then most.
    Can you recommend a good web hosting provider at a fair price?
    Thaanks a lot, I appreciate it!

  3. I simply desired to appreciate you once again. I’m not certain the things that I could possibly have done in the absence of the actual thoughts revealed by you over such a subject matter. Previously it was an absolute distressing concern for me personally, but spending time with a new skilled approach you dealt with the issue took me to leap over fulfillment. I am grateful for this support and thus hope you are aware of a great job you are always putting in teaching others via your web page. I’m certain you’ve never got to know all of us.

  4. This blog is definitely rather handy since I’m at the moment creating an internet floral website – although I am only starting out therefore it’s really fairly small, nothing like this site. Can link to a few of the posts here as they are quite. Thanks much. Zoey Olsen

  5. Great – I should certainly pronounce, impressed with your website. I had no trouble navigating through all the tabs as well as related information ended up being truly easy to do to access. I recently found what I hoped for before you know it at all. Quite unusual. Is likely to appreciate it for those who add forums or something, website theme . a tones way for your customer to communicate. Nice task.

Leave a Reply