admin管理员组文章数量:1122832
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?
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?
Share Improve this question asked Mar 28, 2023 at 12:56 toby1kenobitoby1kenobi 2112 silver badges10 bronze badges1 Answer
Reset to default 0Looks 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
本文标签: sidebarAdd custom settings to widget areas
版权声明:本文标题:sidebar - Add custom settings to widget areas 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736310223a1934299.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论