Theme Options: Add, Remove or Edit an Option

In this article, we’ll reference three functions for adding, removing, and editing theme options.

With all of these functions, whether you’re adding, removing, or editing an option, you must know where that option is located. This means that you’ll need to understand the ID of the tab it belongs to, as well as the ID of the section it belongs to. You can get a good idea how this works by viewing the follwing articles:


Function Reference: themeblvd_add_option

This function allows you to add a single option to an existing section.

Usage
themeblvd_add_option( $tab_id, $section_id, $option_id, $option );
Parameters
$tab_id
(string) (required) ID of tab option will belong to.
Default: None
$section_id
(string) (required) ID of section option will belong to.
Default: None
$option_id
(string) (required) ID of the option to be added.
Default: None
$option
(array) (required) Array for your option, formatted as described in the article, Formatting Options
Default: None
Examples

In the first example, we’ll add simple text field option to Layout > Footer.

themeblvd_add_option('layout', 'footer', 'my_new_option', array(
	'name' 	=> 'Name of your option',
	'desc' 	=> 'Description for your option',
	'id' 	=> 'my_new_option',
	'std' 	=> 'Default value for your option',
	'type' 	=> 'text'
));

Instead of a text field, let’s do a text area, by changing the ‘type’ of our option array.

themeblvd_add_option('layout', 'footer', 'my_new_option', array(
	'name' 	=> 'Name of your option',
	'desc' 	=> 'Description for your option',
	'id' 	=> 'my_new_option',
	'std' 	=> 'Default value for your option',
	'type' 	=> 'textarea'
));

And now, let’s add something more complicated like a select box to Layout > Footer.

themeblvd_add_option('layout', 'footer', 'my_new_option', array(
	'name' 		=> 'Name of your option',
	'desc' 		=> 'Description for your option',
	'id' 		=> 'my_new_option',
	'std' 		=> 'Default value for your option',
	'type' 		=> 'select',
	'options'	=> array(
		'thing_1' => 'Thing 1',
		'thing_2' => 'Thing 2',
		'thing_3' => 'Thing 3',
		'thing_4' => 'Thing 4'
	)
));

Function Reference: themeblvd_remove_option

This function allows you to remove a single option.

Usage
themeblvd_remove_option( $tab_id, $section_id, $option_id );
Parameters
$tab_id
(string) (required) ID of tab where option is located.
Default: None
$section_id
(string) (required) ID of section where option is located.
Default: None
$option_id
(string) (required) ID of option to be removed.
Default: None
Examples

Let’s say you want to remove the option with ID “footer_copyright” located at Layout > Footer.

themeblvd_remove_option('layout', 'footer', 'footer_copyright');

Function Reference: themeblvd_edit_option

This function will allow you to edit part of an option that’s already been setup.

Usage
themeblvd_edit_option( $tab_id, $section_id, $option_id, $att, $value );
Parameters
$tab_id
(string) (required) The ID of the tab the option belongs to.
Default: None
$section_id
(string) (required) The ID of the section the option belongs to.
Default: None
$option_id
(string) (required) The ID of the option being changed.
Default: None
$att
(string) (required) The array key to the attribute being changed of the option.
Default: None
$value
(string) (required) The new value of the attribute being changed.
Default: None
Examples

When your client is setting up their theme options page for the first time, maybe you want it to say something custom for the copyright text, by default. So, let’s change the default value for the option at Layout > Footer > Footer Copyright Text.

Remembering back to the article, Finding Default Option Attributes, we can determine the ID of the option, and the section and tab it belongs to.

Now to fully understand what happening here, let’s have a peek at what we see when we find where this option is set in the framework at /framework/api/class-tb-options-class.php:

From the article, Formatting Options, we know that the std key is where the default value is set with the option array. So, that’s what we’ll be passing in for the $att parameter.

themeblvd_edit_option('layout', 'footer', 'footer_copyright', 'std', 'Your new default text');