Creating Child Themes for WordPress

If you’re unfamiliar with the subject see the Resource Links

A Quck and Dirty Twenty Twelve Child Theme, first we need to create a new folder for the child them, and inside that create a style.css file once done you can follow this example which is a Child Theme for Twenty Twelve.

/*  
Theme Name: Serverhash Twentytwelve
Theme URI: http://www.serverhash.com/serverhash-twentytwelve
Description: Serverhash Twentytwelve theme, based off the twenty twelve theme
Author: James L. Moss Jr.
Author URI: http://www.serverhash.com
Template: twentytwelve
Version: 1.0.0
Tags: light, gray, white, one-column, two-columns, right-sidebar, flexible-width, custom-background, custom-header, custom-menu, editor-style, featured-images, full-width-template, microformats, post-formats, rtl-language-support, sticky-post, theme-options, translation-ready
*/
@import url("../twentytwelve/style.css");

 

Next we can introduce a functions.php file and a custom.css file, this is where all good things begin to happen in custom and child themes. We will keep this basic for now, the code is commented to explain what it’s doing the main purpose is to allow us to include a custom.css file in a correct way.

<?
/**
* Tell WordPress to run post_theme_setup() when the 'after_setup_theme' hook is run.
*/
add_action( 'after_setup_theme', 'serverhash_twentytwelve_post_theme_setup' );
/**
*  Enqueue our own custom.css file
*  Replace the_generator with our own text 
*/
if ( !function_exists( 'serverhash_twentytwelve_post_theme_setup' ) ):
function serverhash_twentytwelve_post_theme_setup() {
// Add our new custom.css styles after all stylesheets have loaded
function serverhash_twentytwelve_enqueue_child_style() {
wp_enqueue_style( 'child_style', get_stylesheet_directory_uri() . '/custom.css', array(), null );
do_action( 'serverhash_twentytwelve_enqueue_child_style', 'child_style' );
}
add_action( 'wp_enqueue_scripts', 'serverhash_twentytwelve_enqueue_child_style', 11 ); 	
// removes the WordPress version from your header for security
function serverhash_twentytwelve_remove_version() {
return <!--Serverhash Twentytwelve, a custom Twentytwelve Child theme -->';
}
add_filter('the_generator', 'serverhash_twentytwelve_remove_version');
}
endif;
?>

 

WordPress Theme Resources:

One key concept for me as a developer and potential theme designer is choosing the right them as a parent theme. Any theme that has it’s own built in theme options needs to either have everything I would want or be easy to extend to fill gaps in needs I may want. To date i’ve simply not found this to be an easy task. So i’m opting for theme’s that by default have no ‘extra’ theme options built into them beyond the basics header/background which are handled easily by default within the wordpress theme api itself and can be kept separate. To this end going foward ill be building up future child themes for the default twenty twelve them and also I will attempt to find a suitable responsive base theme that has ‘no extra theme options’ built in. Allowing me to document the process of adding theme options along the way which as well will lead me down the path of choosing which option framework to use as their are about 5 stable/usefull ones out there which I will be considering. I may try each out and list pro’s cons of each at a later time.

A good example of this is: http://themes.simplethemes.com/skeleton/

Which is a basic responsive theme but comes bundled with an options framework and one of the more complete pre-fab set of options I have found.. I believe most of the www.simplethemes.com themes have been built with that as it’s starting point likely with tweaks as needed, so I will be taking a good look at that as it has alot of nice features i’ll try to recreate but instead from a basic responsive theme as a parent(no options) and adding the extra options/functionality to that with child themes using an options framework.

Why go that route? To me having a parent theme that can be tweaked/updated with minor fixes down the road leaving little to no impact on child themes. Instead strip away the ‘custom aspects’ of a base theme leaving those areas solely to the child theme and me as the developer/designer of that child theme. The parent theme I can help find/suggest tweaks to the themes maintainers and not need to maintain my own version, also I could choose to make my own at a later date. So far i’m leaning towards a responsive base theme. As personally they provide the cleanest starting point with proper webkit shims in place for most browsers. Much more so than twenty twelve does currently. Two main area’s missing in twenty twelve are grids/column defines in the css and also webkit shims for rounded corners, box-shadows, and other IE specific things, which are already done beautifully in responsive themes.

Posted in Web Development and tagged , , , .