Add a "Sidebar" Area for Template Parts
Adds a "Sidebar" area next to Header and Footer in the Site Editor, so sidebar template parts get their own section, icon and the right HTML tag.
Opens WPIDE on
Code
add_filter( 'default_wp_template_part_areas', function ( $areas ) {
foreach ( $areas as $area ) {
if ( isset( $area['area'] ) && 'sidebar' === $area['area'] ) {
return $areas;
}
}
$areas[] = array(
'area' => 'sidebar',
'area_tag' => 'aside',
'label' => 'Sidebar',
'description' => 'Content shown beside the main column, such as widgets or calls to action.',
'icon' => 'sidebar',
);
return $areas;
} );
Notes
Create a template part and choose "Sidebar" as its area in the Advanced panel.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.