WP available widget for certain area

After searching under the tag widget and Google the closest I have found that populates what I am looking for is this article:
Is there a way to allow only certain type of widgets in the sidebars?

I also found this page: How to add a specific widget to only 1 page?.

I reviewed the codex for dynamic_sidebar() and register_sidebar() but I do not see a way when someone goes to the Widgets Panel and under the Available Widgets area you can limit what location a widget can be applied to.

Question: If I want the Tag Cloud widget to only be allowed in a certain registered sidebar, in this case foobar where do I restrict what is allowed?

// Custom widget area for foobar.
if ( function_exists( 'register_sidebar' ) ) {
    register_sidebar( array(
        'name'              => __( 'Foobar Sidebar', 'text_domain'),
        'id'                => 'widget-foobar',
        'description'       => __( 'A custom widget area for foobar', 'text_domain' ),
        'before_widget'     => 'some-code',
        'after_widget'      => 'some-code',
        'before_title'      => 'some-code',
        'after_title'       => 'some-code',
    )); 
}

Or how I can limit custom and default widgets for certain areas I’ve registered?

1 Answer
1

I don’t think it is possible in a nice user friendly way. WordPress admin screen and the customizer assume that any widget can get into any sidebar and will show them as part of the admin, so even if you filter out the widgets you do not want, it will probably create a lot of WTF moments for the user.

I would just suggest not to go that way. If you need to restrict the widgets and you can not count on the user to have self control, then the sidebar/widgets combo might just not be a good answer for what you try to do.

Leave a Comment