Can no longer set sidebar options on Sidebar field
This field is missing the functions to set the options for new sidebars, ie. before_widget, after_widget, etc. At the moment, the only solution is to use the older, deprecated Choose_Sidebar field. Is this the intended behavior?
Hi @smilingpeanut ,
The new field allows changing these options through a filter rather than a method:
$options = apply_filters( 'carbon_custom_sidebar_options', $options, $id );
register_sidebar( $options );
Would you be able to provide an example with a bit more context? I'm trying to do the same thing and am not able to get it to apply any of the custom arguments I've set.
This should do the job:
add_filter( 'carbon_custom_sidebar_options', 'my_custom_sidebar_options', 10, 2 );
function my_custom_sidebar_options( $sidebar_options, $sidebar_id ) {
// see https://codex.wordpress.org/Function_Reference/register_sidebar for more info on the available options
$sidebar_options = array(
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
);
return $sidebar_options;
}
@atanas-angelov-dev This is what occurs when using that code verbatim:
Notice: register_sidebar was called incorrectly. No id was set in the arguments array for the "Sidebar 3" sidebar. Defaulting to "sidebar-3". Manually set the id to "sidebar-3" to silence this notice and keep existing sidebar content. Please see Debugging in WordPress for more information. (This message was added in version 4.2.0.) in [...]/wp/wp-includes/functions.php on line 4138
The options are not applied. Any thoughts?
I'll update this ticket once we have had time to investigate.
Fixed example:
add_filter( 'carbon_custom_sidebar_options', 'my_custom_sidebar_options', 10, 2 );
function my_custom_sidebar_options( $sidebar_options, $sidebar_id ) {
// see https://codex.wordpress.org/Function_Reference/register_sidebar for more info on the available options
$sidebar_options = array_merge( $sidebar_options, array(
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
) );
return $sidebar_options;
}