15

If I use one of the popular frameworks such as Genesis, is it possible to create grandchild themes?

As an example, I want to use Genesis as the backbone of all my sites. Genesis is called a framework but is actually a parent theme.

Then I select one of the Genesis child themes for sale at StudioPress, and want to continue customising it for each of my sites. Would I be creating a grandchild theme for all of my sites, and how would I go about it?

2 Answers 2

19

Sort of "Yes" as a technicality, in practice No.

You can specify a child parent as the parent theme, nothing stops this, and WordPress would attempt to use it.

However

You will run into major issues, not to mention that the core devs have explicitly stated that this is not desirable behaviour, and they will not make efforts to support grandchild themes.

For example, WP API's make a distinction between stylesheet and template URLs/directories, where stylesheet always refers to the active theme, and template refers to the parent theme, but if a grandparent theme is included, does get_template_directory_uri reference the parent or the grandparent? Lots of API calls are now ambiguous, and different people would expect different behaviour, including code that's in core. You'd also need to load the functions.php of either the parent or grandparent, and make sure that it's done in the correct order.

It's also considered very bad practice. If you have a need for grandchild themes then your approach has taken a wrong turn, and you need to step back and re-evaluate things.

I would advise you avoid the concept of grandchild themes, it will lead to more problems. Instead more hooks filters actions and modularity in your child theme should enable you to keep the child themes shared components the same, and let you branch/fork with little difficulty. Try moving common elements into an svn external/git submodule.

There's also the _s model where you have your child theme as a base, and fork it, rather than having it as a parent with the intention you work on the copy, rather than a child/override.

7
  • So in my case if I go with Genesis I'll just have to modify the child theme directly right? Not very familiar with Git, but would be interested in an approach that helps me keep the original child theme intact.
    – urok93
    Sep 21, 2012 at 11:53
  • Yes, you don't have a lot of options here.
    – Tom J Nowell
    Sep 21, 2012 at 12:02
  • I wonder what would happen if you tried to make a great grandchild theme.
    – Chris_O
    Sep 22, 2012 at 15:15
  • 1
    You mention that the method has taken a wrong turn if you need this. The reason I'm curious about this is because of a scenario like using the WooCommerce Storefront theme. They sell child themes to the Storefront them which are customized for various things. So if I'm using one of their child themes, but then I want to go about making my own changes in a way that won't be overwritten when they update their child theme...how would I do that? Jan 31, 2016 at 6:01
  • 1
    I don't know, that's a limitation of how the storefront theme has been built, at that point you're forced to fork the child theme
    – Tom J Nowell
    Jan 31, 2016 at 12:20
3

I did not fully tested the method described below , Nor a normal "grandchild" theme , But giving the functionality of the template_include filter :

    /*
    Plugin Name: Grandchild Themes
    Plugin URI: http://www.who-cares.com/
    Description: A concept for Grandchild themes Plugin
    Author: See Plugin URI
    Version: 0.0.0.0.1-Alpha
    */

    add_action('wp_head', 'grnd_chld_add_headers', 0);
    add_action('init', 'grnd_chld_add_css');

    // Load template if exists. 
function grandchild_template_include( $template ) {

    if ( file_exists( untrailingslashit( plugin_dir_path( __FILE__ ) ) . '/grnd_chld_templates/' . basename( $template ) ) )
        $template = untrailingslashit( plugin_dir_path( __FILE__ ) ) . '/grnd_chld_templates/' . basename( $template );

    return $template;
}

// This is the actual filter that we want .
add_filter( 'template_include', 'grandchild_template_include', 11 );

    function grnd_chld_add_headers () {
        wp_enqueue_style('my_grandchild_style');
    }

    function grnd_chld_add_css() {
        $stamp = @filemtime(plugin_dir_path(__FILE__).'/style.css'); // easy versioning
        wp_register_style ('my_grandchild_style', plugins_url('style.css', __FILE__).'', array(), $stamp);
    }

    // From here , what you got is like a normal functions.php.

You can also, in a similar way , try more specific filters like for example archive_template

add_filter ('archive_template', create_function ('', 'return plugin_dir_path(__FILE__)."archive.php";'));

All that said and done , I am not sure it is the best way to do things .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.