Nuxy
Search…
Adding Frontend Options
Show custom options with setting fields on Front pages
Declare Custom Options
First, you need to declare Options Setup like shown below:
Setup ARRAY structure is the same as Page Options. But it doesn't use filter hook.
1
add_filter( 'wpcfto_get_frontend_settings', 'my_custom_setup', 100 );
2
3
function my_custom_setup( $setups ) {
4
$setups[] = = array(
5
/*
6
* Here we specify option name. It will be a key for storing in wp_options table
7
*/
8
'option_name' => 'my_awesome_settings',
9
10
'title' => esc_html__('Theme options', 'my-domain'),
11
'sub_title' => esc_html__('by StylemixThemes', 'my-domain'),
12
'logo' => 'https://s3.envato.com/files/235051023/avatar-80x80.png',
13
14
/*
15
* Next we add a page to display our awesome settings.
16
* All parameters are required and same as WordPress add_menu_page.
17
*/
18
'page' => array(
19
'page_title' => 'Awesome Settings'
20
),
21
22
/*
23
* And Our fields to display on a page. We use tabs to separate settings on groups.
24
*/
25
'fields' => array(
26
// Even single tab should be specified
27
'tab_1' => array(
28
// And its name obviously
29
'name' => esc_html__('Tab 1', 'my-domain'),
30
'fields' => array(
31
// Field key and its settings. Full info about fields read in documentation.
32
'awesome_1' => array(
33
'type' => 'text',
34
'label' => esc_html__('Awesome Field label', 'my-domain'),
35
'value' => 'Awesome default value',
36
),
37
'awesome_2' => array(
38
'type' => 'text',
39
'label' => esc_html__('Awesome Field label 2', 'my-domain'),
40
'value' => 'Awesome default value 2',
41
),
42
)
43
),
44
45
/*
46
* Other tabs you can add below
47
*/
48
....
49
)
50
);
51
52
return $setups;
53
}
Copied!
Render Options
In order to show options on Front templates, you need to call WPCFTO_Front_Settings::render() function with $option_name parameter on your frontend template:
1
if ( class_exists( 'WPCFTO_Front_Settings' ) ) {
2
WPCFTO_Front_Settings::render( 'my_awesome_settings' );
3
}
Copied!
Last modified 3mo ago
Copy link