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:

add_filter('wpcfto_options_page_setup', function ($setups) {
    $setups[] = array(
        /*
         * Here we specify option name. It will be a key for storing in wp_options table
         */
        'option_name' => 'my_awesome_settings',
        
        'title' => esc_html__('Theme options', 'my-domain'),
        'sub_title' => esc_html__('by StylemixThemes', 'my-domain'),
        'logo' => 'https://s3.envato.com/files/235051023/avatar-80x80.png',

        /*
         * Next we add a page to display our awesome settings.
         * All parameters are required and same as WordPress add_menu_page.
         */
        'page' => array(
            'page_title' => 'Awesome Settings',
            'menu_title' => 'Settings',
            'menu_slug' => 'my_awesome_settings',
            'icon' => 'dashicons-editor-unlink',
            'position' => 40,
        ),

        /*
         * And Our fields to display on a page. We use tabs to separate settings on groups.
         */
        'fields' => array(
            // Even single tab should be specified
            'tab_1' => array(
                // And its name obviously
                'name' => esc_html__('Tab 1', 'my-domain'),
                'fields' => array(
                    // Field key and its settings. Full info about fields read in documentation.
                    'awesome_1' => array(
                        'type' => 'text',
                        'label' => esc_html__('Awesome Field label', 'my-domain'),
                        'value' => 'Awesome default value',
                    ),
                    'awesome_2' => array(
                        'type' => 'text',
                        'label' => esc_html__('Awesome Field label 2', 'my-domain'),
                        'value' => 'Awesome default value 2',
                    ),
                )
            ),

           /*
            * Other tabs you can add below
            */
            // ....
        )
    );

    return $setups;
});

And in your template, you can get your option as:

$my_awesome_options = get_option('my_awesome_settings', array());
/*
 * Where 'my_awesome_settings' is the same setup option name.
 */

Last updated