Extra Step to Make Sure Your WordPress Theme is Child Theme Ready
What is WordPress child theme?
A WordPress child theme is a theme that inherits the functionality of another theme, called the parent theme, and allows you to modify, or add to, the functionality of that parent theme.
Here i will point out couple of extra step you can take to make sure your WordPress Theme is ready to use in child theme development.
1. Add child style.css for your theme
Make sure you include a child-folder inside your WordPress Theme so its easy for other users to create a child theme from your WordPress Theme. its easy, just create a new folder in your theme named child-YOUR-THEME-NAME and add a new style.css inside along with empty screenshots. Content inside child theme style.css should be similiar like this:
/* Theme Name: Theme Name Child Theme URI: http://www.link-to-parent-theme.com Version: 1.0 Description: Child Theme for Parent Theme Name Author: Your Name Author URI: http://www.yoursite.com License: GNU General Public License License URI: http://www.opensource.org/licenses/gpl-license.php Template: Parent-Theme-Name */ @import url("../Parent-Theme-Name/style.css");
2. Proper Action Hooks in Template
This is important for users to add an action hook to your Parent WordPress Theme. Basically its to make the process of editing template layout more convenient and avoid users edits the parent template. You should add do_action() hook to your templates:
<?php do_action('wp_before_content'); ?> <div class='content'> some code here </div> <?php do_action('wp_after_content'); ?>
well, you get the point.
3. template_directory() vs stylesheet_directory()
To make sure any template in parent theme are editable via child theme, you should add condition to your include() file like this:
<?php if( is_child_theme() && 'YOUR-PARENT-THEME-NAME' == get_template() && file_exists( get_stylesheet_directory() . '/custom-functions.php' ) ): include( get_stylesheet_directory() . '/custom-functions.php' ); else: include( get_template_directory() . '/custom-functions.php' ); endif; ?>
Its not necessary to take this extra step to prepared your WordPress Theme for child theme. Framework like Genesis or Thesis use a good example of apply_filter() for their theme templating which is much easier if you know how to use add_filter() WordPress core function. Hopefully, this guide will help you understand more about preparing your theme for child theme usage.