Wordpress Developer

How To Add New Option Types To Option Tree

May 15, 2018

You can do this by adding the following code without ever editing the core files in OptionTree.
When you add new options, there are two requirements.

Step 1:  Function must be prepended with ot_type_:               

 

if ( ! function_exists( ‘ot_type_custom_post_checkbox’ ) ) {function ot_type_custom_post_checkbox( $args = array() ) {/* Add custom code here */
}}

Step 2:  when adding to the array of options your new array keys need to match the function name minus ot_type_,  ot_type_custom_post_checkbox you could add it to the filtered array by following code:                   

 

function unidash_add_custom_option_types( $types ) {
$types['custom_post_checkbox'] = 'Custom Post Type Checkbox option type';
return $types;
}

 

Step3: You can add new option type like another option type in option tree   

array(
‘id’ => ‘search_exclude_cpt’,
‘label’ => esc_html__( ‘Exclude Custom Post Type’, ‘unidash’ ),
‘desc’ => esc_html__( ‘Exclude Custom Post Type from Search Results’, ‘unidash’ ),
‘type’ => ‘custom_post_checkbox’,
‘section’ => ‘search’,
‘operator’ => ‘and’,),

Ok, finally you can create new option types like this:

 

 

 

You Might Also Like