Skip to content

A simple way to create your own WordPress theme options page with tabs (WPML compatible)

Notifications You must be signed in to change notification settings

taunoha/cmb2-theme-options-with-tabs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CMB2 Theme Options Page with Tabs (WPML Compatible)

Description

A simple way to create your own theme options page. This plugin requires CMB2 to work.

Installation

Include cmb-theme-options-tabs library in functions.php or use it as WordPress plugin.

if( defined('CMB2_LOADED') ) {
    require_once('cmb2-theme-options-tabs/cmb-theme-options-tabs.php');
}

Usage

Define your theme options in functions.php

function cmb2_ld_theme_options_fields()
{
    $fields = array(
        array(
            'name'    => '404 page settings',
            'id'      => '_ld_main_404_box_title',
            'type'    => 'title'
        ),
        array(
            'name'    => 'Title',
            'id'      => '_ld_main_404_title',
            'type'    => 'text'
        ),
        array(
            'name'    => 'Content',
            'id'      => '_ld_main_404_content',
            'type'    => 'wysiwyg',
            'options' => array(
                'textarea_rows' => 5
            )
        )
    );

    return $fields;
}
add_filter('cmb2_theme_options_tab_fields', 'cmb2_ld_theme_options_fields');

You can get the options like this:

echo ld_get_theme_option('_ld_main_404_title');

If you prefer to define your own tabs just use cmb2_theme_options_tab_tabs filter to do this. But keep in mind that in this case you have to add additional parameter to ld_get_theme_option() function to get your theme option.

function cmb2_theme_options_tab_tabs_callback($tabs)
{
    return array(
        'global' => array(
            'translated_name' => 'Global',
            'language_code' => 'global'
        )
    );
}
add_filter('cmb2_theme_options_tab_tabs', 'cmb2_theme_options_tab_tabs_callback');

echo ld_get_theme_option('_ld_main_404_title', 'global');

Screenshot

Image

About

A simple way to create your own WordPress theme options page with tabs (WPML compatible)

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages