You must define a valid element for the before_widget
/after_widget
when you register a sidebar. In fact, I just a couple days ago added this to the theme handbook on Widgets: Opting-In To Selective Refresh:
Important: Selective refresh for widgets requires that the theme include a
before_widget
/after_widget
wrapper element around each widget that contains the widget’s ID. Such wrappers are the default when youregister_sidebar()
. For example:
register_sidebar(
array(
'name' => esc_html__( 'Sidebar', 'example' ),
'id' => 'sidebar-1',
'description' => esc_html__( 'Add widgets here.', 'example' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">', // <= Key for selective refresh.
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);