Welcome to Help center

We are here to help

Modify Options in Child Theme

Follow

/*
* Custom function for filtering the sections array. Good for child themes to override or add to the sections.
* Simply include this function in the child themes functions.php file.
*/

function add_another_section($sections) {
$sections['section_key'] = array (
'title' => __( 'A Section added by hook', 'fruitful' ),
'id' => 'section_id'
'fields' => array(
array(
'id' => 'field_id',
'label' => __('Label','fruitful'),
'info' => __('info','fruitful'),
'type' => '',
'default' => '',
'fields' => array()
),
)
);
return $sections;
}
add_filter('settings_fields', 'add_another_section');



section key

Key to each option in the array.Suggests using the key value as the “id” parameter(section_id)

title

Displays title of the section.

section id('id')

Unique ID identifying the section. Must be different from all other section IDs.

fields

Blocks of arrays that represent the individual options within a specific options panel, set via a Sections array

field id('id')

Unique ID identifying the field. Must be different from all other field IDs.

label

Displays title of the field.

info

Description of the option, appearing beneath the field control.

type

Can use types like: text,textarea,checkbox,select,image,color,font,

default

Default value of the field.

fields()

Nested blocks of arrays, set via a field array

description

An additional informative field for checkbox

imagetype

An additional data-imagetype  for image(upload_btn)

box-title

An additional informative field nested blocks

Example custom section with fields 

function child_options($sections) {
$sections['custom'] = array (
'title' => __( 'Custom', 'fruitful' ),
'id' => 'custom',
'fields' => array(
array(
'id' => 'example_text',
'label' => __('Text field','fruitful'),
'info' => __('This is a information for the text input','fruitful'),
'type' => 'text',
'default' => 'Default value',
),
array(
'id' => 'example_textarea',
'label' => __('Example Textarea Input','fruitful'),
'info' => __('This is a information for the textarea input.','fruitful'),
'type' => 'textarea',
'default' => 'Default value',
),
array(
'id' => 'example_checkbox',
'label' => __( 'Example Checkbox' , 'fruitful' ),
'info'          => __( 'This is a information for the checkbox.', 'fruitful' ),
'description' => __( 'This is a description for the checkbox.' , 'fruitful'),
'type' => 'checkbox',
'default' => 'on',
),
array(
'id' => 'example_select',
'label' => __('Example Select','fruitful'),
'info' => __('This is a information for the select.','fruitful'),
'type' => 'select',
'options' =>  array(
'choice1' => __('Choice 1', 'fruitful'),
'choice2' => __('Choice 2', 'fruitful'),
'choice3' => __('Choice 3', 'fruitful'),
),
'default' => 'choice1',
),
array(
'id' => 'example_image',
'label' => __( 'Example image' , 'fruitful' ),
'info' => __( 'This is a information for the upload image.', 'fruitful' ),
'type' => 'image',
'class' => 'upload_btn'
),
array(
'id' => 'example_color',
'label' => __('Example color','fruitful'),
'info' => __('This is a information for the color.','fruitful'),
'type' => 'color',
'default' => '#000000',
),
array(
'id' => 'example_font_family',
'label' =>  __( 'Example Fonts' , 'fruitful' ),
'info' => __( 'This is a information for the fonts.', 'fruitful' ),
'type' => 'font',
'options' => fruitful_fonts_list(),
'default' => 'Open Sans, sans-serif',
),
array(
'id' => 'example_combined_fields',
'label' =>  __( 'Combined fields' , 'fruitful' ),
'info' => __( 'This is a information for the combined fields.', 'fruitful' ),
'fields' =>  array (
array(
'id' => 'example_box1',
'type' => 'text',
'default' => 'Default value',
'box-title' => __( 'This is a box-title for example box1.', 'fruitful' ),
),
array(
'id' => 'example_box2',
'type' => 'color',
'box-title' => __( 'This is a box-title for example box2.', 'fruitful' ),
'default' => '#000000',
),
)
),
   )
);
return $sections;
}
add_filter('settings_fields', 'child_options');


A safe way of getting values for a named option from the options database table is use function fruitful_get_theme_options()

For example:

$theme_options  = fruitful_get_theme_options();
if (isset($theme_options['example_text'])) {
echo 'theme_options['example_text'].';
}

Result:

Default value

Comments

Top
Powered by Zendesk