0

I have two custom widgets a Search_Widget_Page which is created with the following code;

class Search_Widget_Page extends WP_Widget {
    /**
     * Register widget with WordPress.
     */
    function __construct() {
        parent::__construct(
            'Search_Widget_Page',
            __('Search Form - Pages', 'text_domain'),
            array( 'description' => __( 'Add a search form to a page, there must not be another search form in the side bar.', 'text_domain' ), ) // Args
        );
    }

I then have another similar widget that can display in the sidebar, however, I do no want it to display if the widget above is being used on the page. I have tried the following code to no avail;

public function widget( $args, $instance ) {

if( is_active_widget( 'Search_Widget_Page' ) ) { // check if search widget is used

   Do not display this widget

} else {

   Display this widget

}
2

According to the Codex, you may add some additional parameters to is_active_widget() to make it work. So try this one:

if ( is_active_widget(false, false, 'Search_Widget_Page', true) ) { // check if search widget is used

   // Do not display this widget

} else {

   // Display this widget

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.