How To

Grandchildren Themes

The solution to children of children themes is a plugin.

I’m a fan of Genesis themes. They look nice, they’re secure, and they’re well coded. A lot of things I have to reinvent in other themes are done out of the box in Genesis.

But they’re not perfect.

Frameworks Beget Children Themes Frameworks Beget Children Themes

The problem with Genesis themes is that if you use them, you’ll end up using a Child Theme and not Genesis. Unlike boilerplate themes like Underscores, you’re not meant to edit the theme itself but make a child theme.

For the most part, this doesn’t bother me. I don’t generally edit the child themes, except in two cases. Both of my fan sites run highly modified versions of the default themes, and one of them uses the amazing Utility Pro theme by Carrie Dils.

And that was my problem. I knew Carrie was working on a new version which would have some amazing updates. And I? I had forked her theme.

Top ↑

Marrying Forks Marrying Forks

Merging my fork to her new theme had, generally, not been an issue. I’ve updated it a dozen times already and I just run a tool to find the diff between the files. I’m a Coda fan, and I use Comparator to check out the differences between files. Doing this is time consuming and annoying, however, and generally leads to people not making changes they should.

As time went on, I made fewer and fewer changes not because I didn’t want to, but because I had gotten increasingly smarter. Why edit out what I could de-enqueue, for example?

Top ↑

Grandchildren Plugins Grandchildren Plugins

The solution to my woes was a grandchild. Except instead of a grandchild theme, I made a plugin. Actually I have an mu-plugin called “Site Functions” and in that file is this call:

if ( 'Utility Pro' == $theme->name ) {
include_once( dirname( __FILE__ ) . '/utility-pro/functions.php' );

That file has 300-ish lines of code, which sounds like a lot now that I look at it. Except it boils down to 6 actions and 7 filters:

add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'genesis_after_entry_content', array( $this, 'genesis_after_entry_content' ), 15 );
add_action( 'wp_head', array( $this, 'header' ) );
add_action( 'genesis_before_comment_form', array( $this, 'before_comment_form_policy' ) );
add_action( 'genesis_before_comments', array( $this, 'before_comments_ads' ) );
add_action( 'genesis_setup', array( $this, 'theme_setup' ), 20 );

add_filter( 'the_content_more_link', array( $this, 'more_link_text' ) );
add_filter( 'excerpt_more', array( $this, 'more_link_text' ) );
add_filter( 'admin_post_thumbnail_html', array( $this, 'admin_post_thumbnail_html' ) );
add_filter( 'genesis_title_comments', array( $this, 'genesis_title_comments' ) );
add_filter( 'genesis_comment_list_args', array( $this, 'comment_list_args' ) );
add_filter( 'comment_form_defaults', array( $this, 'comment_form_defaults' ) );
add_filter( 'genesis_footer_creds_text', array( $this, 'footer_creds' ), 99 );

Everything I did editing the theme, I can do in those 6 actions and 7 filters. It’s positively amazing. For example, I mentioned dequeueing? I don’t like using Google Fonts if I don’t have to, so I remove them. But I also needed to change the backstretch arguments to properly force my image in the right location, so I can do this:

wp_dequeue_script( 'utility-pro-fonts' );
wp_dequeue_script( 'utility-pro-backstretch-args' );
wp_enqueue_script( 'utility-pro-backstretch-args',  WP_CONTENT_URL . '/mu-plugins/utility-pro/backstretch.args.js', array( 'utility-pro-backstretch' ), '1.3.1', true );

That removes the fonts and backstretch arguments, and then adds my own in. And yes, I know my method of calling mu-plugins is not great. I do it this way because I have symlinks, and plugins_url() manages to call that URL instead of the one I want it to.

Top ↑

The Benefits The Benefits

Doing my code this way means it can’t be deactivated. It also is called by checking the theme, so if that changes then the files stop being called. I keep my own work under version control, letting me go back any time I need to. I’m no longer duplicating Carrie’s work either, speeding up my development time.

It’s a win all around.

3 replies on “Grandchildren Themes”

Great call checking the theme name.
I generally create a regular plugin that can be easily deactivated – I’ve been criticised for not changing the Genesis child theme and there are good arguments on either side (if you can find them amongst the fighting).

I have considered using template_redirect() to override template files in the child theme. I’ve experimented with providing selectable page templates where the template file is not in the child theme directory (not so easy).

I have started using WP-Clips for this when I’m using an existing child theme as opposed to one I create myself. Alas, I didn’t think to do that when I built my own site with Utility Pro, so I had to do that diff/merge stuff, myself. Learned my lesson after that.

Comments are closed.