Nuxy
Search…
Adding Page Options
Add custom admin page with setting fields
Theme Options
The framework will create a menu or submenu item in the WordPress menu. The script will auto-load itself on the correct admin hooks. You need to add a filter with next parameters:
1
add_filter('wpcfto_options_page_setup', function ($setups) {
2
$setups[] = array(
3
/*
4
* Here we specify option name. It will be a key for storing in wp_options table
5
*/
6
'option_name' => 'my_awesome_settings',
7
8
'title' => esc_html__('Theme options', 'my-domain'),
9
'sub_title' => esc_html__('by StylemixThemes', 'my-domain'),
10
'logo' => 'https://s3.envato.com/files/235051023/avatar-80x80.png',
11
12
/*
13
* Next we add a page to display our awesome settings.
14
* All parameters are required and same as WordPress add_menu_page.
15
*/
16
'page' => array(
17
'page_title' => 'Awesome Settings',
18
'menu_title' => 'Settings',
19
'menu_slug' => 'my_awesome_settings',
20
'icon' => 'dashicons-editor-unlink',
21
'position' => 40,
22
),
23
24
/*
25
* And Our fields to display on a page. We use tabs to separate settings on groups.
26
*/
27
'fields' => array(
28
// Even single tab should be specified
29
'tab_1' => array(
30
// And its name obviously
31
'name' => esc_html__('Tab 1', 'my-domain'),
32
'fields' => array(
33
// Field key and its settings. Full info about fields read in documentation.
34
'awesome_1' => array(
35
'type' => 'text',
36
'label' => esc_html__('Awesome Field label', 'my-domain'),
37
'value' => 'Awesome default value',
38
),
39
'awesome_2' => array(
40
'type' => 'text',
41
'label' => esc_html__('Awesome Field label 2', 'my-domain'),
42
'value' => 'Awesome default value 2',
43
),
44
)
45
),
46
47
/*
48
* Other tabs you can add below
49
*/
50
....
51
)
52
);
53
54
return $setups;
55
});
Copied!
And in your template, you can get your option as:
1
$my_awesome_options = get_option('my_awesome_settings', array());
2
/*
3
* Where 'my_awesome_settings' is the same setup option name.
4
*/
Copied!
Last modified 10mo ago
Copy link