0

Is it possible to add a checkbox to all widgets loaded into sidebars? For example, I'd like to allow the site owner to choose whether any widget should appear on the home page, inside pages, both or neither.

I'm thinking a checkbox interface appended to the widget control interface.

Has anyone done something like this and what level of complexity are we talking?

1 Answer 1

0

There are plugins that can do this like Widget Context or Widget Logic.

If you want your own solution then it's pretty easy:

  • hook your function with the checkbox on in_widget_form
  • hook your widget update function widget_update_callback (update the widget option)
  • check if the option was checked using the widget_display_callback hook (return false if it is)

Post what you have so far if you need sample code. I've implemented a feature like this in one of my themes...

3
  • Thanks, I'll check out the plugins for some examples. In your outline, is that widget-specific or a global function that would intercept any widget that's updated?
    – N2Mystic
    Commented Jun 30, 2011 at 1:01
  • it's global, works for all widgets using the 2.8 api... Commented Jun 30, 2011 at 1:36
  • Thanks for your help! I've taken your suggestions and got a pretty good start. I'd welcome your code example or any pointers you might have. I've posted the code here > wordpress.stackexchange.com/questions/21975/…
    – N2Mystic
    Commented Jul 4, 2011 at 21:33

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.