1

The condition is i have to check the id of active widgets of one sidebar and hide some widgets based on id of the listed widgets.Any ideas ...

2
  • 2
    What have you tried and where have you failed. We expect you to have at least tried something yourself :-) Commented Sep 17, 2015 at 10:35
  • I have tried is_active_widget but doesnot work for custom widgets
    – clap
    Commented Sep 17, 2015 at 10:42

1 Answer 1

2

Despite what you say is_active_widget does work on custom widgets as well. You may just have trouble locating its ID. To help you, here's a snippet that will show the ID of a widget on the widget admin.

add_action('in_widget_form', 'wpse202950_get_widget_id');

function wpse202950_get_widget_id($widget_instance) {
    if ($widget_instance->number=="__i__"){
        echo '<p class="widget-id-message">' . __('Save the widget to get its ID','textdomain') . '</p>';
        }
    else {
        echo '<p class="widget-id-message">' . __('The widget ID is:','textdomain') . ' ' . $widget_instance->id . '</p>';
        }
    }

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.