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.