WordPress : API de personnalisation et add_panel(). Le panneau ne s’affiche pas
J’essaie d’ajouter un panneau à mon personnalisateur mais le code ci-dessous ne fonctionne pas (le panneau ne s’affiche pas dans le conteneur du personnalisateur). Mon 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',
) );
}
Solution n°1 trouvée
Tout d’abord, utilisez un identifiant différent pour votre panneau que panel_id
.
Vos sections ne s’afficheront pas sans les commandes et paramètres associés, et les panneaux ne s’afficheront pas sans les sections associées.
Essayez d’ajouter des contrôles à chaque section et cela devrait résoudre votre problème.
Solution n°2 trouvée
Vous voulez ajouter_setting et add_control à votre panneau pour fonctionner.
Par exemple:
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');
Solution n°3 trouvée
Ce morceau de code fonctionne pour moi
<? 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' );
?>
0 commentaire