For example, I want Sidebar A to display nothing but one text widget and Sidebar B to display anything but text widgets. How can I do that?
Thanks.
For example, I want Sidebar A to display nothing but one text widget and Sidebar B to display anything but text widgets. How can I do that?
Thanks.
Comments are closed.
It is possible to hook to
sidebars_widgets
and find which widget is in which sidebar.By checking that array you could eliminate particular widgets.
That works front end, and back end, but does not prevent a widget from being dragged into the wrong sidebar on the back end. That is, you can still drag a widget into the wrong sidebar and have it appear to work, but it will be removed on next page load. To solve that issue you will need to construct some Javascript to prevent the drag or issue some kind of warning.
WordPress admin panel has three widgets area:
In order to set a widget undroppable when it’s coming from “all available widget” or “inactive widgets” to a “wrong” sidebar simply use .widget class and an id to identify it.
I need to set the “Custom Recent Posts” widget undroppable so:
Drag from: available widgets area, inactive widgets area
That’s ok, but what’s happen with the active widgets?
These widgets are not affected by “drag”, but “sort”. This part was little tricky, it is possible that my solution is not cool, but it works : )
I need to set “Custom Recent Posts” widget not sortable ( you do a drag, in jquery logic is a sort ):
Drag/Sort from within the active widgets:
I needed the same logic within my project, I’m testing now and it seems to work like expected try it : )
Hope it helps