Title: [Plugin: OptionTree] Default form values?
Last modified: August 19, 2016

---

# [Plugin: OptionTree] Default form values?

 *  Resolved [johnb41](https://wordpress.org/support/users/johnb41/)
 * (@johnb41)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/plugin-optiontree-default-form-values/)
 * I love this plugin from what I’ve seen so far. But I don’t know if it’s usable
   for “me” until I get this resolved:
 * My current (old) Theme Options has some default values set (default text for 
   textareas, default dropdown lists selected, etc.) It would be great if after 
   the user uploads the XML for their site, that certain things would be pre-populated.
   Am I missing something, or is such a thing not supported?
 * [http://wordpress.org/extend/plugins/option-tree/](http://wordpress.org/extend/plugins/option-tree/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Derek Herman](https://wordpress.org/support/users/valendesigns/)
 * (@valendesigns)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/plugin-optiontree-default-form-values/#post-1815794)
 * Default values are created when you save the data and export it to an XML file.
   They become the defaults when the user imports the XMl file. Basically, you create
   the defaults yourself when you have saved all the basic settings and export them.
 *  [thelumberjack](https://wordpress.org/support/users/thelumberjack/)
 * (@thelumberjack)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/plugin-optiontree-default-form-values/#post-1815834)
 * I know I’m a little bit late to the party, but I thought I’d drop in some code
   that may prove handy for anybody looking for a way to set actual default values
   on their options.
 * So here is how to display an option in your template (I’m using a Twitter account
   as the option for this example):
 *     ```
       if ( function_exists( 'get_option_tree' ) ) {
           get_option_tree( 'twitter', '', true );
       }
       ```
   
 * To display a default value, simple drop this line of code underneath and edit
   accordingly:
 *     ```
       [EDIT] Hold that thought. I found an error in my code.
       ```
   
 * Now, if a value is not set, it will default to “th3lumberjack”. Hopefully somebody
   out there finds this useful.
 * : )
 *  [thelumberjack](https://wordpress.org/support/users/thelumberjack/)
 * (@thelumberjack)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/plugin-optiontree-default-form-values/#post-1815835)
 * Try this instead:
 *     ```
       $otest = get_option_tree( 'twitter' );
   
       if ($otest == "") {
           echo("th3lumberjack");
       }
       ```
   
 * $otest is simply a variable for testing the result.
 *  [Flaunt Books](https://wordpress.org/support/users/skooks/)
 * (@skooks)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/plugin-optiontree-default-form-values/#post-1815836)
 * Another way to achieve greater speed and simplicity is this code below:
    Add 
   this to the functions.php file in your theme:
 *     ```
       if ( function_exists( 'get_option_tree' ) ) {
         $theme_options = $theme_options;
       }
   
       function option_tree_default($val,$default){
       	global theme_options;
       	if($theme_options[$val]){
       		return $theme_options[$val];
       	}else{
       		return $default;
       	}
       }
       ```
   
 * Then within you theme you can use it as such:
    `echo 'option_tree_default('my_var_value','
   Default Value');`
 *  [Flaunt Books](https://wordpress.org/support/users/skooks/)
 * (@skooks)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/plugin-optiontree-default-form-values/#post-1815837)
 * I think the important issue behind default values is that the end-user is potentially
   hazardous to the site operations when they remove important values, insert wrong
   values, insert improperly formatted values (colors, measurements), etc.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘[Plugin: OptionTree] Default form values?’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/option-tree_363534.svg)
 * [OptionTree](https://wordpress.org/plugins/option-tree/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/option-tree/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/option-tree/)
 * [Active Topics](https://wordpress.org/support/plugin/option-tree/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/option-tree/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/option-tree/reviews/)

 * 5 replies
 * 4 participants
 * Last reply from: [Flaunt Books](https://wordpress.org/support/users/skooks/)
 * Last activity: [15 years, 1 month ago](https://wordpress.org/support/topic/plugin-optiontree-default-form-values/#post-1815837)
 * Status: resolved