Title: Remove widget from sidebar before render
Last modified: August 24, 2016

---

# Remove widget from sidebar before render

 *  [gabron](https://wordpress.org/support/users/gabron/)
 * (@gabron)
 * [11 years ago](https://wordpress.org/support/topic/remove-widget-from-sidebar-before-render/)
 * 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.

 * 0 replies
 * 1 participant
 * Last reply from: [gabron](https://wordpress.org/support/users/gabron/)
 * Last activity: [11 years ago](https://wordpress.org/support/topic/remove-widget-from-sidebar-before-render/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
