Add Multiple Widget Areas

Rather than include this boilerplate code in my starter theme, I’m saving it here so that I can copy and paste it when I need to.

The array_map function will iterate over $widget_areas, meaning one iteration is one widget area, and passes the widget area configuration to the Genesis function genesis_register_widget_area.

<?php
/**
* Register widget areas.
*
* @uses genesis_register_widget_area()
*
* @since 1.0.0
*/
add_action( 'widgets_init', function () {
$widget_areas = [
[
'id' => 'example-widget-area',
'name' => __( 'Example Widget Area', 'generico' ),
'description' => __( 'This is an example widget area, it\'s not used for anything in particular.', 'generico' ),
],
[
'id' => 'another-widget-area',
'name' => __( 'Another Widget Area', 'generico' ),
'description' => __( 'This is another example widget area, it\'s not used for anything in particular.', 'generico' ),
]
];
array_map( 'genesis_register_widget_area', $widget_areas );
}, 5 );
view raw functions.php hosted with ❤ by GitHub

Reader Interactions

Leave a Reply

Your email address will not be published. Required fields are marked *