Hello,
This actually sounds like a bit of a theme issue. It is pretty standard in a WordPress theme that when you register your sidebar you want to have the “before_widget” argument contain the ID of the current widget and standard classes in the markup.
Also note that when you call register_sidebar
in your theme to setup the sidebar, if you don’t override the “before_sidebar” argument, WordPress already does this for you by default.
So, this means that in your theme when the sidebar is registered, the theme author has (a) passed in their own “before_widget” argument and (b) didn’t include the id="%1$s"
part.
For example, if you were you to call register_sidebar()
with no arguments passed in, WordPress will use the following arguments by default:
$args = array(
'name' => __( 'Sidebar name', 'theme_text_domain' ),
'id' => 'unique-sidebar-id',
'description' => '',
'class' => '',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>'
);
If you want to adjust the “before_widget” and “after_widget” markup in a theme, that’s totally fine, but just make sure that you always include the ID and standard classes in the surrounding markup something like this:
$args = array(
'name' => __( 'Your Sidebar', 'theme_text_domain' ),
'id' => 'your-sidebar',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>'
);
register_sidebar( $args );
This will ensure that widget plugins out there that rely on $before_widget
parameter when displaying the widget will work more consistently with your theme.