In the vein of my earlier post on simplifying the code for displaying multiple widget areas in Genesis, I share the condensed code for registering 4 widget areas here.
// Register front-page widget areas
for ( $i = 1; $i <= 4; $i++ ) {
genesis_register_widget_area(
array(
'id' => "front-page-{$i}",
'name' => __( "Front Page {$i}", 'my-theme-text-domain' ),
'description' => __( "This is the front page {$i} section.", 'my-theme-text-domain' ),
)
);
}
(goes in child theme’s functions.php)
The above is the same as
genesis_register_widget_area(
array(
'id' => "front-page-1",
'name' => __( "Front Page 1", 'my-theme-text-domain' ),
'description' => __( "This is the front page 1 section.", 'my-theme-text-domain' ),
)
);
genesis_register_widget_area(
array(
'id' => "front-page-2",
'name' => __( "Front Page 2", 'my-theme-text-domain' ),
'description' => __( "This is the front page 2 section.", 'my-theme-text-domain' ),
)
);
genesis_register_widget_area(
array(
'id' => "front-page-3",
'name' => __( "Front Page 3", 'my-theme-text-domain' ),
'description' => __( "This is the front page 3 section.", 'my-theme-text-domain' ),
)
);
genesis_register_widget_area(
array(
'id' => "front-page-4",
'name' => __( "Front Page 4", 'my-theme-text-domain' ),
'description' => __( "This is the front page 4 section.", 'my-theme-text-domain' ),
)
);
Insanely easy.
You surprised me Sridhar. Once more.
That looks easy enough, can you post how to hook it into a custom homepage for a custom child theme?
You can create a front-page.php having code based on the one at https://sridharkatakam.com/full-width-page-template-in-genesis-for-beaver-builder/.
You’d display the widget areas under
[php]// Display Content[/php]
For a practical example, see https://sridharkatakam.com/adding-background-images-multiple-widget-sections-via-customizer-genesis/ (members-only).
[…] https://sridharkatakam.com/simplifying-code-registering-multiple-widget-areas-genesis/ […]
[…] 5 widget areas using a for loop: ad-1, ad-2, ad-3, ad-4 and […]