3 Ways To Remove Sidebar Widgets

If you’ve hook in a widget using an add_action in your parent or child theme, you can generally remove it using a remove action.

Generally, you would also include a conditional tag after the function in the first place so no need to even remove it.

But what if you added the widget using a filter in the first place?

You can’t use a remove_action to remove the widget if it was added using a filter so you need another solution which is the sidebars_widget filter.

$sidebars_widgets = apply_filters('sidebars_widgets', $sidebars_widgets);

Filter sidebars_widgets

Here’s the code which you can use in your functions file or directly in a page template:

Unset Widget using sidebars_widgets Filter

Another option is to unset the widget like this:

Unregister Sidebar

If you want to completely unregister a widget which is added from your parent theme, use this code in your child themes functions file.

Remove Specific Widget

The following code enables you to remove 1 or more widgets from any sidebar widget area.

add_filter( 'sidebars_widgets', 'remove_specific_widget' );
     
    function remove_specific_widget( $sidebars_widgets ) {
     
       if ( is_front_page()) 
     
            foreach( $sidebars_widgets as $widget_area => $widget_list ){
     
                foreach( $widget_list as $pos => $widget_id ){
     
                    if ( $widget_id == 'calendar-35'){
     
                        unset( $sidebars_widgets[$widget_area][$pos] );
                    }
                }
            }
         
        return $sidebars_widgets;
    }

Simply swap out the dynamic widget i.d calendar-35 in the above PHP code with your widget i.d you can grab by inspecting the widget.

The code above only removes the calendar widget from the front page.

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.