salcode / bootstrap-genesis

WordPress Genesis Child Theme setup to use Bootstrap, Sass, and Grunt
MIT License
184 stars 63 forks source link

Unable to add widget area #98

Closed salcode closed 9 years ago

salcode commented 9 years ago

I received the following bug report.

for some odd reason I can't add widget areas, am I doing something wrong? I keep getting the white screen of death whenever I do genesis_register_sidebar.

At this point, this issue needs to be researched and recreated.

salcode commented 9 years ago

I'm guessing the white screen of death is due to calling genesis_register_sidebar() before the Genesis files are loaded by WordPress.

The following code adds a widget area

add_action( 'genesis_setup', 'test_bsg_add_widget_area', 15 );
function test_bsg_add_widget_area() {
    genesis_register_sidebar( array(
        'id'        => 'test_bsg_widget_area',
        'name'      => __( 'Test BSG Widget Area', 'bsg' ),
    ) );
}

If the genesis_register_sidebar() function is called without the function wrapped around it, i.e. it executes as soon as functions.php runs and does not wait for the genesis_setup hook, the site will have a fatal error and display the white screen.

Use generic widget_area rather than sidebar

Instead of genesis_register_sidebar(), it is preferable to use genesis_register_widget_area() making the code

add_action( 'genesis_setup', 'test_bsg_add_widget_area', 15 );
function test_bsg_add_widget_area() {
    genesis_register_widget_area( array(
        'id'        => 'test_bsg_widget_area',
        'name'      => __( 'Test BSG Widget Area', 'bsg' ),
    ) );
}

Both functions do the same thing (genesis_register_sidebar() is an alias for genesis_register_widget_area). The sidebar version remains for backwards compatibility.

JacoVintage commented 9 years ago

Thanks Sal, this is now resolved.

salcode commented 9 years ago

@JacoVintage glad to hear it, thanks for the note.