1

I'd like to add settings to sidebars defined in my custom theme - sometimes, for example, I'd like to be able to set a widget area to not display. Is this possible, I can't find any references for it?

1 Answer 1

0

Looks like it is not something that is supported in WordPress. Pretty much the only thing that can be set for the whole Sidebar that is displayed in the admin UI is the title and description. Description allows some basic HTML (like <a>, <b>, <em> etc.) but there is no way to render form controls there and they would not be saved anyway.

WordPress however, has support to add settings for individual Widgets in Sidebars. This may be less intuitive as it is not really a setting for the whole sidebar. You can use the in_widget_form action to render such settings and the widget_update_callback filter to save them for individual Widgets. Than you can simply return false in the widget_display_callback filter to prevent the widget from being shown, based on your setting. Check out this tutorial for more details on adding custom Widget setting to control their display.

Note that this only applies to legacy Widgets. If the new Block (Gutenberg) editor is used it is possible to add blocks to sidebars, and those blocks will not have such settings. Find details about how the Gutenberg sidebar editor is different than the classic one here

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.