1

i tried to create more than one section in Theme Customizer, but had no success with that.

/* Theme customize - Create menu bar link */
function example_customizer_menu() { add_theme_page( 'Customize', 'Customize', 'edit_theme_options', 'customize.php' ); }
add_action( 'admin_menu', 'example_customizer_menu' );

How i got it for all of new sections (tabs) in Theme Customizer i must to write code below. Is it right?

/* Create one new tab */
add_action('customize_register', 'themedemo_customize');
function themedemo_customize($wp_customize) {

$wp_customize->add_section( 'themedemo_demo_settings', array(
    'title'          => 'Demonstration Stuff',
    'priority'       => 35,
) );

$wp_customize->add_setting( 'some_setting', array(
    'default'        => 'default_value',
) );

$wp_customize->add_control( 'some_setting', array(
    'label'   => 'Text Setting',
    'section' => 'themedemo_demo_settings',
    'type'    => 'text',
) );

$wp_customize->add_section( 'themedemo_demo_settings', array(
    'title'          => 'Demonstration Stuff',
    'priority'       => 40,
) );

$wp_customize->add_setting( 'some_other_setting', array(
    'default'        => '#000000',
) );

$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'some_other_setting', array(
    'label'   => 'Color Setting',
    'section' => 'themedemo_demo_settings',
    'settings'   => 'some_other_setting',
) ) );

}

For what did we use "customize_register" and why there is always different words? How i got it "themedemo_customize" it is like parameter here..

add_action('customize_register', 'themedemo_customize');
function themedemo_customize($wp_customize) {

I read official documentation but did not get it.

1 Answer 1

1

The hook customize_register is for include all your custom settings to the default core settings. Your code is a good start, Hook, there init a function, there include all settings, and sections. But you register 2 section areas with the same ID; there is wrong. If you will create two different sections on the customizer, then create also two different key, IDs for the sections - $wp_customize->add_section. A exmaple:

    // Set option key based on get_stylesheet()
    $this->theme_key  = $args['theme_key'];
    $this->option_key = $this->theme_key . '_theme_options';

    // ===== Layout Section =====
    // Option for leave sidebar left or right
    $wp_customize->add_section( $this->option_key . '_layout', array(
        'title'       => __( 'Layout', 'documentation' ),
        'description' => __( 'Define main Layout', 'documentation' ),
        'priority'    => 30
    ) );

    // ===== Custom Section =====
    // create custom section for rewrite url
    $wp_customize->add_section( $this->option_key . '_rewrite_url', array(
        'title'       => __( 'Rewrite', 'documentation' ),
        'priority'    => 35,
    ) );

You can create many sections, how yoo want and register also different options per section. Maybe you see on this example for a ready usable solution:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.