1

I try to add panel to my customizer but code below doesn't work (panel don't show in customizer container). My code:

add_action( 'customize_register', 'customizer_test' );
function customizer_test($wp_customize) {
    $wp_customize->add_panel( 'panel_id', array(
        'priority'       => 10,
        'capability'     => 'edit_theme_options',
        'title'          => __('Theme Options', 'mytheme'),
        'description'    => __('Several settings pertaining my theme', 'mytheme'),
    ) );
    //sections
    $wp_customize->add_section( 'header_settings', array(
        'priority'       => 10,
        'capability'     => 'edit_theme_options',
        'title'          => __('Header Settings', 'mytheme'),
        'description'    =>  __('Header elements configuration', 'mytheme'),
        'panel'  => 'panel_id',
    ) );

    $wp_customize->add_section( 'footer_settings', array(
        'priority'       => 10,
        'capability'     => 'edit_theme_options',
        'title'          => __('Footer Settings', 'mytheme'),
        'description'    =>  __('Footer elements configuration', 'mytheme'),
        'panel'  => 'panel_id',
    ) );

}
  • Please read How to Ask - then file an edit and rephrase your question and explain what "does not work" and how it fails. – kaiser Feb 23 '15 at 14:29
  • Ok I fix this. The panel doesn't show because I don't add any controls to my section. – Michał Kalkowski Feb 23 '15 at 14:29
6

You want to add_setting and add_control to your panel to work.

For example:

function panel($wp_customize){

$wp_customize->add_panel('some_panel',array(
    'title'=>'Panel1',
    'description'=> 'This is panel Description',
    'priority'=> 10,
));


$wp_customize->add_section('section',array(
    'title'=>'section',
    'priority'=>10,
    'panel'=>'some_panel',
));


$wp_customize->add_setting('setting_demo',array(
    'defaule'=>'a',
));


$wp_customize->add_control('contrl_demo',array(
    'label'=>'Text',
    'type'=>'text',
    'section'=>'section',
    'settings'=>'setting_demo',
));}   add_action('customize_register','panel');
| improve this answer | |
3

First, use a different id for your panel than panel_id.

Your sections will not show up without associated controls and settings, and panels will not show up without associated sections.

Try adding controls to each section and that should fix your issue.

| improve this answer | |
0

This piece of code work for me

<? php
        
/**
  * Add panel | custom section and settings
  */
function firstest_news_theme_customize_register( $wp_customize ) {
        // add panel
        // Add Theme Options Panel.
        $wp_customize->add_panel( 'theme_option_panel',
            array(
                'title'      => esc_html__( 'Theme Options', 'wp-firstest-news-theme' ),
                'priority'   => 20,
                'capability' => 'edit_theme_options',
            )
        );
    
        // Global Section Start.*/
    
        $wp_customize->add_section( 'social_option_section_settings',
            array(
                'title'      => esc_html__( 'Social Profile Options', 'wp_firstest_news_theme' ),
                'priority'   => 120,
                'capability' => 'edit_theme_options',
                'panel'      => 'theme_option_panel', //Refence to panel above
            )
        );
    
                /*Social Profile*/
                $wp_customize->add_setting( 'social_profile',
                    array(
                        'default'           => $default['social_profile'],
                        'capability'        => 'edit_theme_options'
                        // 'sanitize_callback' => 'wp_firstest_news_theme_sanitize_checkbox',
                    )
                );
                $wp_customize->add_control( 'social_profile',
                    array(
                        'label'    => esc_html__( 'Global Social Profile ( Nav Right )', 'wp-firstest-news-theme' ),
                        'section'  => 'social_option_section_settings',
                        'type'     => 'checkbox',
    
                    )
                );
    
        // Global section start **************************
       $wp_customize->add_section('theme-option', array(
         'title' => __('Edit Carousel', 'wp-firstest-news-theme'),
         'description' => sprintf(__('Options for showcase', 'wp-firstest-news-theme')),
         'priority' => 130,
         'capability' => 'edit_theme_options',
         'panel'      => 'theme_option_panel' 
       ));
    
       // Add image slider
       $wp_customize->add_setting('slider_1_image', array(
         'default'  => get_bloginfo('template_directory') . '/img/shocase1.jpg', 'wp-firstest-news-theme',
         'type'     => 'theme_mod'
       ));
    
       // Add control
       $wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'slider_1_image', array(
         'label'    =>esc_html( __('Slider Image 1', 'wp-firstest-news-theme')),
         'section'  => 'theme-option',
         'setting' => 'slider_1_image',
         'priority' => 1
       )));
    
       // Add settings slider 1 heading
       $wp_customize->add_setting('showcase_1_heading', array(
         'default'  => _x('Another example headline.', 'wp-firstest-news-theme'),
         'type'     => 'theme_mod'
       ));
    
       // Add control
       $wp_customize->add_control('showcase_1_heading', array(
         'label'    => esc_html(__('heading', 'wp-firstest-news-theme')),
         'section'  => 'theme-option',
         'priority' => 2
       ));
    }
     add_action( 'customize_register', 'firstest_news_theme_customize_register' );
    
     ?>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.