August 5, 2009

Adding Theme Options To WordPress Child Themes

Please note: the following is “experimental”, although it has been tested and seems to be working, it was tested only briefly. This post is more to share the idea and see if I can’t get feedback to improve or reformat the idea. I am sure there is a good chance something like this has been implemented out there somewhere.

Since creating my own WordPress framework for personal and business use I have been constantly considering theme options. What is necessary, what is not and what my be limiting in terms of future development. I have always come to the same conclusion. That is, to go minimal on the framework theme options, limiting it to the basics that would be useful no matter the theme you create from the framework. Things like SEO, Analytics inserts etc.

This left me with a question. What if certain theme options make sense when developing future themes from the framework?

Let me back up a minute it is important that I note I am talking about a framework from which I create themes via Child Theme. Basically this means I create a theme which uses the framework as a template but without actually touching the framework theme files. See this post on ThemeShaper for further information.

Ok so back to the question, how do I keep the framework options minimal and allow the addition of new theme options to the existing options through the child theme?

This morning after some work I believe I stumbled on a solution. Have a look at the files below starting with the framework theme options page here. Pay close attention to the following lines…


$childoptions = apply_filters('childtheme_options_test', $childoptions);
$options = wp_parse_args( $childoptions, $options);

This is condensed version of the options setup for example purposes only, for further info on this please see this post.


// Create theme options
$options = array (
   				
                   array(  "name" => "General",
                              "type" => "heading"),
					    
                   array(  "type" => "open"),
   				    
                   array(  "name" => "Logo",
                              "desc" => "Enter the full path to your custom logo here.",
                              "id" => $shortname."_logo",
                              "std"; => " ",
                              "type" => "text", ),

                   array( "type" => "close"),
                      
              );
$childoptions = apply_filters('childtheme_options_test', $childoptions);
$options = wp_parse_args( $childoptions, $options);

Now you will see in the child theme functions file where I was able to add a filter, basically adding new options to the theme without modifying the framework.


function child_options_test() {	
$shortname = "etm";
$options = array (

                   array(  "name" => "Test",
                              "type" => "heading"),
					    
                   array(  "type" => "open" ),
   					
                   array(  "name" => "Test",
                              "desc" => "Enter custom text here.",
                              "id" => $shortname."_logo",
                              "std"; => " ",
                              "type" => "text", ),
   					
                   array( "type" => "close"),
   		);
   		return $options;
  }
add_filter('childtheme_options_test', 'child_options_test');

Finally I would hook the output of this new option to the theme framework in the desired place via a new child theme function.

Before you implement this I will say, I do not recommend it without doing your own testing. I have tested it and it seems to work as planned, however this post was not meant to be a tutorial. What I am looking for here is some feedback on the implementation to see if it has merit or if there is a smarter way to go about this.

Please feel free to comment below or contact me with your thoughts on this implementation.

Recommend that you check out the Options Framework Plugin by Devin at WP Theming.

22 thoughts on “Adding Theme Options To WordPress Child Themes

  1. This was a cool trick. I had a different way to define theme options but after playing around I saw this actually worked great. I have extra child theme options.

    One thing that I think will not work is trying to put multiple options (extra options) for existing ones and at different places. will need to do more research on placements.

  2. Nice, I would love to hear what you discover. I have changed up how my base theme handles options quite a bit since I posted this and have been experimenting with hooks and such that allow me to add theme options to my child themes. Also I have tried to eliminate anything but the basics(universal options) from my base theme options allowing me to keep it simple only adding options if absolutely necessary and entirely through the child theme. I will more than likely release a theme in the future with this new handling but for now it’s mostly used on personal projects and in testing. I do feel like there is a way that you could manipulate options that are already in place if you found a need for doing this. It would of course have to be built into the framework that way. Let me know what you figure out and thanks for the comment!

  3. Hello

    This is a great way to define options in a theme.

    I wanted to know if it is possible to create child themes of existing child themes. What I meant was that I’m already using a theme which is a child theme. I wanted to make some changes to the child theme and instead of modifying the child theme files I thought it would be better if I create a child theme of an existing child theme. Is this possible as it does not seem to be working for me.

    Thanks in advance.

    Pali Madra

  4. Hi Pali – Thanks for the comment. You pose an interesting question here, one I’ve had to think about before replying and have a feeling I still will not give the greatest answer.

    For starters I would have a look at these two discussions http://www.wptavern.com/forum/themes-templates/464-grand-child-themes.html and http://ptahdunbar.com/wordpress/on-using-wordpress-theme-frameworks/.

    In my personal opinion I am not sure that I see it being necessary nor would I look to attempt it if it is in fact possible. It seems to me that most child themes are built with the idea that code modification is minimal and the majority of the child theme concentrates on design accomplished via css. The heavy lifting is accomplished by the core/parent theme, thus the only reason that a child theme might need to be upgraded is if there was a major change in the parent theme. For instance themename-hook-header gets the axe, said child theme happens to hook into themename-hook-header and on upgrade of the parent theme there are problems. That doesn’t take into account that the theme framework author would more than likely deprecate the function thus making it available for some time there after. (Ideally all of this would be well documented and easy to follow.)

    That aside, let’s say at this point the original child theme author decides to upgrade the child theme to account for the parent theme change, it would more than likely be very minimal and something you could take care of in a matter of minutes without actually needing to undergo a full upgrade of the child theme as well.

    I’m rambling here but hopefully that makes some sense. I think the idea here is to protect the parent theme from core modification, leaving the child theme to allow you to do what you would like with it. Ultimately if the original parent theme was well planned and upgrades are well documented then any absolutely necessary upgrades to the child theme should be minimal and easy to maintain without having to undergo a full upgrade.

    I suppose that if the original base child theme was some extreme modification of the parent theme, then there might be reason for concern but even then I am not sure.

    Hopefully that helps in your decision, definitely read the two linked posts as well and let me know what you decide to do.

  5. Hi Jeremy. Thanks for posting the thoughtful reply to Pali’s question. I would agree with the remarks in the Tavern. Once you get two child themes deep, you’re then making modifications of modifications? Seems very complicated and indirect.

  6. Exactly, it seems like it would start a perpetual cycle. Let’s say Grandchild themes are possible – Parent theme get’s upgraded with something major so the original child theme get’s upgraded leading to the possibility that the grandchild theme now needs an upgrade so where do you stop? It would be my opinion that the child theme should be the end point. If you were looking at modifying the child theme css file only, I suppose that you could do so by adding a new style sheet and hooking that into the head. As long as you set the order correctly you could potentially modify the child theme without actually modifying the child theme, if that makes sense.

  7. Jeremy,

    Thank you for replying to comment. The community of WordPress thrives on participation from people like you. I want to assure you the comments you have made are not rambling in fact they are interesting and I have read your comment thrice!

    I have gone through the links and some of the people specially those of Green Shady. After going through the content provided by you I have understood the concept of Frameworks and Child Themes better.

    I also agree that creating “grand child” themes would be like taking the concept too far and implementing child themes would be complex and it is unlikely that it would be a smooth process.

    Therefore I have decided for the particular project to go in for modifying the child theme. Actually it is a child theme developed by StudioPress. I will keep you posted on how it goes.

    Please advise if you think it is not the correct decision.

    Thanks once again. You have one more fan now.

    Pali Madra

  8. Pali –

    You are welcome, I enjoy getting into discussions like this. For starters anything by StudioPress is obviously an extremely solid theme to start with, plus you know that it’s going to come with good documentation and history of changes whenever an upgrade is performed. It doesn’t hurt to know that it is also a solid company behind the theme that I don’t see disappearing anytime in the near future. That aside I would be interested to hear their thoughts on recommended course of action for modification given that it looks like they will be porting all of their themes to the Genesis Framework as child themes.

    Have you attempted to start a discussion on this in the support forum, or even tried reaching out to one of the developers via Twitter to ask opinions? All parties involved in the StudioPress company are top notch when it comes to WordPress knowledge so like I said, I would definitely be interested to hear their recommendations.

    Don’t hesitate to drop by and leave updates on this thread, find me on Twitter or even email me if you would like. I took interest in the child theme concept when frameworks like Thematic and Hybrid came to be and started promoting the idea. Since then I have more or less developed my own adaptation of a framework that works best for my development style but of course I am still very interested to see how others work with frameworks and child themes so please feel free to come by for discussion as you work through this project.

    Look forward to you coming back around in the future and thanks again for starting this conversation.

  9. Excellent post, very rare topic, even a year later.

    I have this working perfectly on a new theme for WordPress 3.0.

    Cheers!

  10. Brian –

    Thank for leaving a comment, glad you found the post useful and good to hear it’s still working in 3.0! It depends somewhat on how the parent theme creates options in the first place I suppose, none the less I know this works with a few of them out there.

    Jeremy

  11. Hi Jeremy,

    Very nice post.. thank you.

    I’ve been trying to figure out how to add options to the thematic theme framework without amending thematic. Your solution, whilst elegant, would entail me adding code to thematic itself would it not?

    Do you have any advice regarding extending thematic options without amending the thematic code?

    Thanks,

    Michael.

  12. Michael –

    Thanks for the comment. To tell you the truth it’s been quite a while since I had a look at Thematic and I’m not even certain I have the most current version.

    You are correct it did mean adding code which I realize more or less defeats the purpose of the framework/child theme situation. I think my original intention was to look for a solution that didn’t require the addition of a separate child theme options page even though I believe that might have been recommended at the time. (Having two seem a bit much) I think I also figured it easy enough to “auto” upgrade 99% of the framework and manually pick through the theme-options.php code if it required upgrade.

    It’s definitely something worth exploring. Have you had a look at the link Devin left above? Looks like he’s recently updated his Thematic theme options. Not sure how it’s been done but definitely looks nice, you may want to check it out.

    Thematic Options Panel.

    None the less if you dig into this and figure a solution please don’t hesitate to drop a comment or shoot me an email. I always like an interesting problem.

  13. Thanks Jeremy,

    Yes, I did have a look at Devin’s link. As it goes he’s produced a lovely thematic child theme but, again, this won’t exactly solve my puzzle since it’s the option panels in my thematic child themes I want to enhance. Were I to use Devin’s theme I would lose mine in the process. I could, of course, use the relevant part of his theme as a starting point for making my own. .perhaps I’ll try that.

    Hmm.. interesting, I actually quite like the idea of an additional child theme options menu item with my particular options therein. Thematic options are listed in the menu as ‘Thematic options’, an additional menu item named ‘my client’s theme options’ may do the trick nicely.

    Sure, as I develop my solution I will post my findings here..

    Thanks again for a great post and informative discussion.

    Go well,

    m.

  14. Ah, well then actually it works out quite well and I have done it this way before. Basically you create a second options panel and do just that, name it “my child theme options”. Based on my experience I was very easily able to integrate the child theme options into the theme without actually touching the framework. All options and their respective output was added via the child theme functions file.

    Just a note I found it best to include (require) a secondary child-theme-options.php and create a child theme “lib” directory to keep everything nice and tidy.

    Look forward to hearing back from you when you create your solution and glad you found this post helpful as a starting point.

  15. Hi Michael. The Thematic Options Panel I built is a child theme of Thematic. All the options are entirely in the child theme. It doesn’t require any edits to core Thematic code.

    All it does is unhook the default Thematic options, and put this new one in its place.

    What Jeremy said is right on. You could even remove the code where I unhook the Thematic options if for some reason you wanted both (though I think that would be confusing for the user).

  16. Devin, thanks for jumping in. That in my opinion is the perfect solution. Everything consolidated in one options panel and the ability to add new options easily.

    Makes me feel like my post here might be a bit confusing as your solution is really the ideal way of doing things in my opinion. Devin on that note would you mind if I added a little disclaimer to the top here that directs people to your post stating that a better solution has been created?

    Nice work on that options panel by the way looks great, I’m going to have to download it and have a look around.

  17. Chris has been working on an API for the options which will hopefully provide some more hooks.

    I think the solution you posted is great if you just need to add a few items- but if someone wants to do a lot of options and really have control of the layout I think it’s better to just unhook it entirely and put a new one in it’s place.

  18. – Devin..

    The Thematic Options Panel I built is a child theme of Thematic. All the options are entirely in the child theme. It doesn’t require any edits to core Thematic code.

    Sure, I get that. Yet what I need is additional options (somewhat like yours) in my Thematic child theme(s). If I adopt your child theme then I’d need to develop my themes as Thematic->Your Child Theme->My Grand-child theme(s), as it were, which is undesirable of course.. or or am I missing something?

    All it does is unhook the default Thematic options, and put this new one in its place.

    Ah ha! If I were to have a look at and replicate your ‘unhooking’ and ‘putting new ones in place’ code I could replace the Thematic options with my own, just as you have.. make sense?

    Michael.

  19. I’m sure Devin will jump in to answer this one but I think you’ve got it with the second statement. You don’t necessarily need to use his child theme or replicate his options exactly but the general idea behind his solution could be adapted to work with your own child themes.

  20. Thanks for the comment on this, I’m sure you might get a few answers on how to do this but have you had a look at this page on the StudioPress dev site Creating New Settings. It would be my personal recommendation to follow their lead and instruction on how to add new settings for child themes. From there it’s just a matter of creating and registering the new settings and like it mentions on that page, use the Genesis settings as a foundation for building.

Comments are closed.