Check if the current shortcode is being used in a widget
There are two hooks, widget_text and dynamic_sidebar_params. You can use one of them. add_filter( ‘widget_text’, ‘wpse219770_filter_widget_text’, 1, 3 ); function wpse219770_filter_widget_text( $widget_text, $instance, $widget ) { $tag = ‘bartag’;//shortcode tag if ( ‘text-2’ == $widget->id && has_shortcode( $instance[‘text’], $tag ) ) remove_shortcode( $tag ); else add_shortcode( $tag, ‘bartag_func’ ); return $widget_text; } Or you can … Read more