• Sorry in advance if this not the right sub-forum.

    I have a widget provided by a plugin that I have overridden. I want to add it to two widget areas, but I want it to behave differently depending on which area it is in. (In my case display images on the sidebar, not display them in the footer). I’m hoping there is a quick way to determine which area is running the widget? Or maybe a way to pass that state variable?

    I’d rather not clone the whole widget.

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Joey

    (@leglesslizard)

    Hey,

    Sorry if I misunderstand but to place the widget into 2 different widget areas aren’t you going to be “cloning” the widget regardless?

    Two (possibly) quick solutions come to mind:
    I obviously don’t know your exact use case but I would look at either finding/coding a separate widget so that each area has it’s own widget behaving how I want them to
    OR
    Hide/show the elements of the widgets using css/js to output the desired effect.

    I would have a look at the plugin itself, however, as many people supply you with hooks and filters to adjust the output of such things before it is returned. The author may have implemented something that enables you to do what you want.

    Hope that helps some!
    Joey

    Moderator bcworkz

    (@bcworkz)

    I think the best way to deal with this is to add a checkbox to the admin settings form regarding whether to display images or not. For the widget in the sidebar it is checked and for the footer it is not. Form settings are readily available in $instance of the widget() method. Which sidebar is calling the widget is very much not readily available.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Widget variant issue’ is closed to new replies.