2

Using the block-based widget editor, how do I add a widget title? I wish to make the title a link to collapse the widget body using bootstrap and register_sidebar:

register_sidebar([
  'name' => __('Main Sidebar', 'blog'),
  'id' => 'main-sidebar',
  'description' => __('Main sidebar widget area', 'blog'),
  'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  'after_widget' => '<hr class="wp-block-separator my-5 is-style-wide"></div></aside>',
  'before_title' =>
    '<h3 class="widget-title"><a data-bs-toggle="collapse" href="#widget%1$s" role="button" aria-expanded="false" aria-controls="widget%1$s"><div id="widget%1$s">',
  'after_title' => '</a></h3>',
]);

But I see no way to add a title unless using legacy widgets. Has this field been removed?

0

1 Answer 1

1

But I see no way to add a title unless using legacy widgets.

Correct, legacy old style widgets have titles, normal blocks do not because they are not widgets.

Note that old style widgets are actually blocks of type core/legacy-widget. Everything is a block.

Has this field been removed?

No, it was never there to begin with.

It's not that blocks can now be widgets. It's the widgets can now be blocks. The new sidebar areas contain blocks, not widgets. Some of these blocks are a compatibility block named legacy-widget, which will render handle titles etc. You can see that here. Unlike before, sidebars are now block HTML markup, the same as posts. Legacy widgets may still refer to the old method of storing widgets but other blocks store data the same as they would elsewhere.

As for normal blocks that are not widgets, giving them each a title doesn't make sense unless the design explicitly states that blocks are widgets, and it does not. Anybody with such a mental model of how modern widget areas work is mistaken.

If you want blocks to be surrounded by widget titles and widget markup, you should build a block for that which supports nested blocks.

In the longterm, consider widget areas a legacy backwards compatibility feature. The future is reusable blocks, or FSE templates.

2
  • Thank you for clarifying how this now works. By removing markup from register_sidebar, and adding it instead to the sidebar using the block editor, I now have things functioning as I had expected.
    – gpcola
    Commented Sep 11, 2021 at 16:54
  • UPDATE: The widget group block in an upcoming version with a header block. Install and activate the latest gutenberg plugin and check it by putting your blocks inside a widget group block with a heading make.wordpress.org/core/2021/09/22/… it may only get you part way though, but it's something that can be picked up on by stylesheets
    – Tom J Nowell
    Commented Sep 23, 2021 at 9:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.