WordPress 5.8 Block-Based Widgets: Disable Classic Widgets, Filter Output, and WP_Widget Compatibility

Block-based widgets in WordPress 5.8: switch back or adapt

WordPress 5.8 replaced the classic Widgets screen with a block editor: widget areas are now edited like posts, with blocks, and classic widgets are shown inside a “Legacy Widget” block. For many sites this works out of the box. For some it breaks things: themes that style widgets with the classic markup, plugins whose widget forms rely on the old screen, and clients who were used to the old interface.

Problem: After the update to 5.8, a plugin’s widget settings no longer save correctly in the new Widgets screen, and the theme’s sidebar markup changed.

Solution: Switch back to the classic Widgets screen with the use_widgets_block_editor filter while the plugin is not compatible, or adapt the theme to the block widgets with dynamic_sidebar_before / dynamic_sidebar_after and the widget_block_content filter.

Back to classic widgets

<?php
add_filter( 'use_widgets_block_editor', '__return_false' );

This restores the classic Widgets screen and the classic widgets in the Customizer. The official Classic Widgets plugin does exactly the same. It is a good temporary solution; most widget plugins added support for the new screen within months.

Keeping the block widgets

Each block in a widget area is wrapped in the sidebar’s before_widget and after_widget markup, like a classic widget. Wrappers around the whole area and changes to the block output are done with hooks:

<?php
add_action( 'dynamic_sidebar_before', function ( $index, $has_widgets ) {
    if ( $has_widgets ) {
        echo '<div class="widget-area widget-area--' . esc_attr( $index ) . '">';
    }
}, 10, 2 );

add_action( 'dynamic_sidebar_after', function ( $index, $has_widgets ) {
    if ( $has_widgets ) {
        echo '</div>';
    }
}, 10, 2 );

// The rendered HTML of each block widget
add_filter( 'widget_block_content', function ( $content, $instance, $widget ) {
    return '<div class="block-widget-inner">' . $content . '</div>';
}, 10, 3 );

Classic widgets registered with register_widget() keep working and appear in the inserter under their names, inside a Legacy Widget block.

Hiding classic widgets that have a block equivalent

Core already hides classic widgets that have a block version (Archives, Categories, Search…). Your own widget can be hidden from the Legacy Widget block in the same way once you have a block that replaces it:

<?php
add_filter( 'widget_types_to_hide_from_legacy_widget_block', function ( $widget_types ) {
    $widget_types[] = 'ha_social_links'; // the ID base of the widget
    return $widget_types;
} );

Themes without widget support for blocks

A theme can opt out on its own, for example when its sidebars are designed only for classic widgets:

<?php
add_action( 'after_setup_theme', function () {
    remove_theme_support( 'widgets-block-editor' );
} );

NOTE: Switching to classic widgets does not convert anything: blocks already added to widget areas stay as block widgets and are still shown on the site. Check the widget areas after switching, and remove or recreate blocks that should be classic widgets.