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 use this methode:
add_action( 'dynamic_sidebar_params', 'wpse219770_dynamic_sidebar_params_hook', 1, 1 );
function wpse219770_dynamic_sidebar_params_hook( $content )
{
//print_r( $content ) and use it for conditional
$tag = 'bartag';
if ( shortcode_exists( $tag ) )
remove_shortcode( $tag );
return $content;
}
Related Posts:
- Shortcode from a widget is wrapped in unwanted element
- How can I whitelist only specific shortcodes for processing in text widgets?
- When to use which plugin output method?
- Custom shortcode in widget forced to top of widget
- is_active_sidebar() Always Returns False
- Shortcode in Text Widget not working
- Inserting shortcode [stream /] into a Text widget
- How to insert widget areas specific to certain pages (or posts, etc.)?
- check for shortcode in post/pages AND widgets AND template files
- Closest thing to an is_widget() tag?
- the_widget() and widget’s ID
- How the widget can be run by shortcode
- How do i display the built-in gallery inside a widget?
- Shortcode displays always first. Once again
- Create a widget to use shortcode?
- Display custom widget, added as a shortcode in the correct place
- Conditional Tags Based on Previously Viewed Posts
- Allow shortcode for custom widget
- Shortcode not working in widget
- Display a widget on a specific type of archive
- Different sidebars not changing
- call widget from within shortcode
- How to get number of posts in same category as current post?
- Transform php shortcode into a widget [duplicate]
- Can I use widgets & shortcode if I need to return an array?
- page url in shortcode
- How do I get shortcode, widget and template tag CSS to load in the head only as required? [duplicate]
- Using Conditional Tags to restrict something to 1 user?
- How to load Widget javascript + css files only if used?
- Adding iframe Content to Sidebar Widget
- How to use wp_dequeue_style() for style enqueued in WP_Widget class
- Storing custom dashboard widget options in wordpress
- Create a Widget Area in the Navigation Bar for the Genesis Theme Framework?
- Manual display of widget
- Customized widget area – how to override or filter class xoxo?
- How to access widget data from outside widget?
- How to add a description to Widgets?
- How do I stop a widget from displaying on mobile site?
- cannot drag and drop widgets since wordpress 3.2.1
- Color Picker Showing Twice When Widget Added to Sidebar
- Widget modifications in a child theme
- How to get “Widget Logic” plugin’s input value in a custom widget code (to display on the Widget admin page)
- How to make this change without changing the core? [duplicate]
- Add pagination to listing plugin
- how to put functions inside of widgets
- Adding a Widget : what to put in plugin URL
- How to list all custom post types in a custom widget?
- How can I assign widgets from WP to appear in bbpress?
- How to extend WP_Widget_Media
- Dynamic created widget id value of multi-instance in jQuery
- Color picker in widget appears twice when added via the Customizer
- Hide widget (and white space) on specific resolution [closed]
- Adding Widgets to Draft Pages
- How to select multiple media files for a widget form?
- Apply code for all else first block
- Programmatically add widgets to sidebars
- Are widgets meant to be used outside of sidebars?
- Is there a WordPress widget for my webpage?
- FTP Widget Location
- Inserting Read More Tag in Widget
- dynamic sidebar in front page
- Create Widget or Enable Shortcodes in Sidebar
- Display posts from category in post content?
- How to add shortcode to html widget
- display widget checkbox selection on frontend
- Enabled checkbox by default in WordPress widgets
- Is there a way to use get_sidebar() when no widgets are activated?
- Widget background images missing on second blog excerpt page
- How should I add a “widget” like element?
- modifying title (in dashboard) for different widget instances
- How to translate Widget Description in constructor?
- What conditional to use for dynamic sidebar check?
- Trouble accessing a multidimensional array to add classes to default WordPress widgets
- links to Media Library content in sidebar per page
- Why is registering a sidebar for each page causing my sidebars to reset?
- How do I customize the positioning of WordPress widgets?
- Limit archive widget results
- Quick Draft widget in weird place on dashboard after being re-added
- Fatal error: Uncaught Error: Class ‘WP_Widget’ not found
- Remove widgets on mobile front page without affecting desktop
- Widget display nothing
- How can I have sidebar widgets on Twenty Seventeen theme on all pages?
- Collapsible widgets [closed]
- Loop through Widgets in sidebar using widget array number?
- Is it ok not to set widget in the main page of a one page WordPress Theme?
- How to get widget content in WordPress based on it’s ID?
- New Custom Widget Call a Different Widget Function
- Loading scripts only if a particular shortcode or widget is present
- Always show the widget title in a wordpress widget
- Custom php Widget keeps disappearing from the front end
- Display Posts by Views (Popular Posts Widget)
- Insert to wp_footer if widget is found in the sidebar
- Using javascript on the new widget preview / customizer page
- Show editor widgets only on pages that use a specific template?
- Conditionally enable autoplay when using oEmbed in a custom widget
- Custom tabs widget don’t work in google chrome, is blocked, do not change the tabs. Why?
- WordPress Hide Widget If $_Session Is Active?
- Recent posts with different class name for each post and a scrollbar?
- Classic widgets with 5.9+?
- is it possible to create custom widgets page in admin?