Creating a Child Theme in WordPress – alternate methods

In a previous post I elucidated the tried and trusted method of creating a child theme in WordPress.  In this article we are not going into the “why” of a child-theme, only the how.

The manual way

Again, the purpose is as much for me to not forget, as it is about to be generally useful :).  As explained in my previous article, first you create a theme directory, and then a style.css file in that directory.  The style.css file makes sure that the theme is recognized by WordPress, and that it is indeed a child theme.  As an example, we will create a Child of the Twenty Fifteen theme to be used in a site at example.com.  We will call this theme “example-twenty-fifteen”.

As indicated earlier, when activating this new theme, none of parent styling is showing up.   The traditional way of fixing this was with an @import statement in the style.css file, like so:

/*
Theme Name: Example Twenty Fifteen
Version: 1.0
Description: A child theme of Twenty Fifteen
Template: twentyfifteen
*/

@import url("../twentyfifteen/style.css");

An alternate way is to NOT use @import, but instead, create a functions.php for the child theme and add the following code:

<?php

/* handle parent stylesheet */
//this replaces the old method of @import a style sheet

add_action('wp_enqueue_scripts','theme_enqueue_styles');
function theme_enqueue_styles() {
	wp_enqueue_style( 'parent-style', get_template_directory_url() .'/style.css' );
	wp_enqueue_style( 'child-style', get_stylesheet_uri(), array( 'parent_style' ) );
}

Use a plugin

I like the “Child Themify” plugin.  It does directory creation, and style.css creation for you.  Plus it copies the screenshot.png file from the parent.

Child Themify - Create a Child

Child Themify – Create a Child

 Child Themify - Name the Child

Child Themify – Name the Child

Child Theme Activated

Child Theme Activated

The “Child Themify” plugin creates a style.css file with the @import stanza in it.  The plugin can be deactivated once the child has been created.

And that’s it.  Enjoy.

 

One Response to “Creating a Child Theme in WordPress – alternate methods”

  1. … [Trackback]

    […] Read More Infos here: drmagu.com/creating-a-child-theme-in-wordpress-alternate-methods-1331.htm […]

Leave a Reply

You must be logged in to post a comment.