How do I add/edit/remove theme options?
There are two types of theme options. You have the global theme options on the Theme Options page and you have the individual options on individual pages.
Global Theme Options
This theme uses the Redux framework for the options interface. Redux provide documentation on adding, editing and removing options or sections here: https://docs.reduxframework.com/core/redux-api/
Adding A Section
Add the following to your child theme's functions.php file:
$opt_name = 'option_name'; // Change this value to the option name, you can find this in functions.php e.g. $gp = get_option( 'option_name' ); $section = array( 'title' => 'New Section', 'id' => 'new-section', 'desc' => '', 'icon' => 'el el-home', 'fields' => array( array( 'id' => 'opt-text-example', 'type' => 'text', 'title' => 'Text Field', 'subtitle' => 'Subtitle', 'desc' => 'Field Description', 'default' => 'Default Text', ), array( 'id' => 'opt-select-example', 'type' => 'select', 'title' => 'Dropdown Field', 'subtitle' => 'Subtitle', 'desc' => 'Field Description', 'options' => array( 'one' => 'One', 'two' => 'Two', 'Three' => 'Three', ), 'default' => 'one', ), ) ); Redux::setSection( $opt_name, $section );
Replacing $opt_name with the theme's option name - you can find this in functions.php e.g. $gp = get_option( 'option_name' ); where 'option_name' is the the value to use.
To call your custom options in your theme you can use:
$opt_name['opt-text-example'];
Again replacing $opt_name with the theme's option name and replacing 'opt-text-example' with the option ID.
Removing A Section
Add the following to your child theme's functions.php file:
Redux::removeSection( $opt_name, $id, $all_fields );
Replacing $opt_name with the theme's option name and $id with the ID of the option you want to remove. You will find all the option IDs in wp-content/plugins/THEME-plugin/inc/theme-config.php.
You can find a full list of all the ways you can edit the theme options at https://docs.reduxframework.com/core/redux-api/
Individual Page Options
Adding A Section
In this example we're going to add a new options panel to individual pages. Add the following to your child theme's functions.php file:
function ghostpool_custom_metabox_options( $metaboxes ) { $new_options = array(); $new_options[] = array( 'fields' => array( array( 'id' => 'opt-text-example', 'type' => 'text', 'title' => 'Text Field', 'desc' => 'field Description', ), array( 'id' => 'opt-select-example', 'type' => 'select', 'title' => 'Dropdown Field', 'subtitle' => 'Subtitle', 'desc' => 'Field Description', 'options' => array( 'one' => 'One', 'two' => 'Two', 'Three' => 'Three', ), 'default' => 'one', ), ), ); $metaboxes[] = array( 'id' => 'new-options', 'title' => 'New Options', 'post_types' => array( 'page' ), 'position' => 'normal', 'priority' => 'high', 'sections' => $new_options, ); return $metaboxes; } add_filter( 'ghostpool_redux_metabox_options', 'ghostpool_custom_metabox_options', 2 );
Replacing $new_options and 'new-options' with unique names.
You can add multiple post types to 'post_types' option including your custom post types e.g..
'post_types' => array( 'page', 'post', 'custom_post_type' ),
To call your custom options in your theme you can use:
<?php echo redux_post_meta( 'opt_name', get_the_ID(), 'opt-text-example' ); ?>
Replacing 'opt_name' with the theme's option names and 'opt-text-example' with option ID.
If "redux_post_meta" does not work try this instead:
<?php echo get_post_meta( get_the_ID(), 'opt-text-example', true ); ?>
Editing/Removing A Section
In this example we're going to edit the slide page options by removing several options. Add the following to your child theme's functions.php:
function ghostpool_custom_metabox_options( $metaboxes ) { $slide_options = array(); $slide_options[] = array( 'fields' => array( array( 'id' => 'slide_caption_title', 'type' => 'text', 'title' => 'Caption Title', 'desc' => 'The caption title for the slide.', ), ), ); $metaboxes[] = array( 'id' => 'slide-options', 'title' => 'Slide Options', 'post_types' => array( 'gp_slide' ), 'position' => 'normal', 'priority' => 'high', 'sections' => $slide_options, ); return $metaboxes; } add_filter( 'ghostpool_redux_metabox_options', 'ghostpool_custom_metabox_options', 2 );
Taxonomy Options
Adding An Option
In this example we're going to add a new option to post and portfolio category pages. Add the following to your child theme's functions.php file:
function ghostpool_custom_category_options( $gp_options ) { $gp_options[] = array( 'id' => 'custom-option', 'name' => 'Custom Option', 'desc' => 'Custom option description.', 'type' => 'select', 'tax' => array( 'category', 'gp_portfolios' ), 'options' => array( 'option-1' => 'Option 1', 'option-2' => 'Option 2', ), 'default' => 'option-1', ); return $gp_options; } add_filter( 'ghostpool_custom_category_options', 'ghostpool_custom_category_options' );
You can specify what taxonomies your options are shown on by changing the 'tax' option e.g.
'tax' => array( 'category', 'post_tag', 'gp_portfolios', 'gp_hubs', 'gp_videos' ),