Simplifying the code for registering multiple widget areas in Genesis

Posted on
5/5 - (163 votes)

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' ),
	)
);