• gabron

    (@gabron)


    Hello, I have 2 same widgets called advert-1 and advert-2 placed in sidebar called advert-box. One of theme is master advert and the second appear only on some pages. I need to remove the master widget if there is additional advert. I have tried:

    function widget_params( $widgets )
    {
    	if (array_key_exists(AdboxWidget::NAME, $widgets)) {
    		$adboxWidgets = $widgets[AdboxWidget::NAME];
    
    		if (count($adboxWidgets) > 1) {
    			unset($adboxWidgets[0]);
    		}
    	}
    	return $widgets;
    }
    add_filter( 'sidebars_widgets', 'widget_params' );

    and it select the first widget. The others are removed. But if I do that it fail in widget_context.php in method maybe_unset_widgets_by_context.

    Do anyone know how to remove the widget?

The topic ‘Remove widget from sidebar before render’ is closed to new replies.