Cleanly Adapting WordPress Child Themes

Soon, themes based on Hybrid Core will be parent themes and it will be easy to adapt them to your own requirements by creating a child theme. If you choose to use Prototype, a parent theme that already uses the latest version of Hybrid Core, you can do this already.

However, there are some excellent child themes based on the old Theme Hybrid way of doing things. Justin agrees that these are not straightforward to update.

"This is a new direction you’ll see from Theme Hybrid. Rather than releasing many complex child themes that are impossible to update, new themes will be parent themes. What this means is that you can make modifications to the themes with your own child theme. The goal has always been upgradibility, and that’s what I’d like to aim for with all themes."

my_functions.php

When I need to modify a complex (e.g. theme hybrid based) child theme I load a new file called my_functions.php at the end of functions.php. I borrowed this idea from Ian Stewart’s Travailler, although I’m sure it’s been used many times before.

/** my_functions.php **/

function add_my_functions() {

    $my_functions_path = STYLESHEETPATH . '/my_functions.php';
    if (file_exists($my_functions_path)) {
        require_once($my_functions_path);
    }
}

add_action('wp_head', 'add_my_functions');

Then you can adapt the child theme from a clean starting point using my-functions.php. For example:

<?php

function my_byline($byline = '') {
    global $post;

    $byline = "[Empty Byline]";
    return $byline;
}

add_filter('hybrid_byline', 'my_byline');

?>

Patchwork by net_efekt

This entry was posted in WordPress and tagged , , . Bookmark the permalink. Both comments and trackbacks are currently closed.