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.
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.
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!
Thanks for the post on this. I just put some work into creating a Thematic child theme with 3 default options for a adding a logo, selecting stylesheets, and google analytics. I also built it to be easily expandable for additional options. Free free to check out the code and use it:
http://wordpresstheming.com/2009/10/thematic-theme-options-panel/