I write a template and I want to create a panel like widgets panel for footer. I register some sidebar which represent the columns of the footer and I want to create a panel which contains section for each footer Column sidebar. I try to use wp_widget_area_customize_control but when i add a widgets, nothing be happen. I don't know if i should use another section class or what and what setting use. Can someone help me please?
-
Why aren't you just using widgets? Widget areas are already added to the customizer automatically.– Jacob PeattieCommented Feb 5, 2023 at 14:07
-
Because I want to separate my theme settings with the default WordPress settings to facilitate access to the thème setting . I add a header panel and now I want to add a footer panel🙂– ryanCommented Feb 25, 2023 at 1:45
1 Answer
It sounds like you are trying to create a custom WordPress panel that will display your footer widget areas. To achieve this, you will need to create a custom section in your WordPress Customizer that will be responsible for displaying the widgets. You can use the WP_Customize_Section class to create your custom section, and the WP_Customize_Control class to create a custom control for your widgets.
Here is a basic example of how you can create a custom section for your footer widgets:
class Footer_Widgets_Section extends WP_Customize_Section {
public $type = 'footer_widgets';
public function render_content() {
// Your code to render the section content
}
}
class Footer_Widgets_Control extends WP_Customize_Control {
public $type = 'footer_widgets';
public function render_content() {
// Your code to render the control content
}
}
// Register your custom section and control
add_action( 'customize_register', function ( $wp_customize ) {
$wp_customize->add_section(
new Footer_Widgets_Section(
$wp_customize,
'footer_widgets',
array(
'title' => __( 'Footer Widgets' ),
'priority' => 30,
)
)
);
$wp_customize->add_setting(
'footer_widgets',
array(
'default' => '',
)
);
$wp_customize->add_control(
new Footer_Widgets_Control(
$wp_customize,
'footer_widgets',
array(
'section' => 'footer_widgets',
'label' => __( 'Footer Widgets' ),
)
)
);
} );
This is just a basic example to get you started. You will need to add more code to the render_content methods of both the section and control to actually display the widget areas and allow the user to add widgets to them.
-
<<it sounds like you are trying to create a custom WordPress panel that will display your footer widget areas.>> Yes it IS what I try to do but I think that WordPress already add control and section to do this like the widgets panel– ryanCommented Feb 25, 2023 at 1:54