There actually are several ways to handle the WordPress editor wrapping shortcodes in <p> tags.
This code shows probably the simplest way to do it…just a simple and short function you need to drop into your functions.php file. Once you do, no more tags around your shortcodes that are on their own line!
function wpex_clean_shortcodes($content){
$array = array (
'<p>[' => '[',
']</p>' => ']',
']<br />' => ']'
);
$content = strtr($content, $array);
return $content;
}
add_filter('the_content', 'wpex_clean_shortcodes');
Source: http://www.wpexplorer.com/snippet/clean-wordpress-shortcodes
Hope that helps someone!
Related Posts:
- Shortcodes within the sidebar text/html widget: How to preserve the raw HTML output of the shortcode?
- Extend WordPress 3.8 Site Activity Dashboard Widget to include more comments
- Add filter to blogroll widget
- How to add a filter to all widget output
- Woocommerce Product Category Widget – hide categories that have no products in stock [closed]
- How can I whitelist only specific shortcodes for processing in text widgets?
- Updating to Version 4.5 bumped my “main sidebar” widget out of place
- When to use which plugin output method?
- Custom shortcode in widget forced to top of widget
- Format content value from DB outside of WordPress filters
- Unfiltered html in widget title not working
- Why does WP not like my container?
- Shortcode in Text Widget not working
- Widget Area: Modify $param[‘xy’] from widget-$n
- Inserting shortcode [stream /] into a Text widget
- WordPress: Apply filter/hook to a particular sidebar widgets?
- check for shortcode in post/pages AND widgets AND template files
- How to add Shortcode (font awesome) in widget title?
- the_widget() and widget’s ID
- Trying to wrap around first word of multiple word strings with a widget_title() filter, only works on two word strings and not more than two
- How the widget can be run by shortcode
- How do i display the built-in gallery inside a widget?
- Disable widgets on specific posts
- Shortcode displays always first. Once again
- Excluding specific widgets from default sidebar class
- Create a widget to use shortcode?
- Check if the current shortcode is being used in a widget
- Display custom widget, added as a shortcode in the correct place
- Need help using a filter on the default Categories widget
- Allow shortcode for custom widget
- Issue understanding and using WordPress filters and actions
- Shortcode not working in widget
- Filter Text from sidebar widget?
- Why would apply_filters return a non-empty string, when the value returned is empty?
- call widget from within shortcode
- recent comments filter by author, page, category
- How to completely prevent WordPress from destroying/modifying my shortcode outputs?
- Pass widget variable to external function
- 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]
- Full Width Container Colour Problems
- Give Editor Access To Sidebar
- How to edit widgets in WordPress
- Complex widget form UI – examples and best practices
- Is it possible to remove the filter from 4.8 text widget?
- Add New Footer Widget Area with Limited Options?
- Add div class to only one widget
- How to use control_callback when creating a widget via functions.php or plugin?
- Gallery Settings Change available Columns
- Shortcodes not resolved in AJAX call response
- Ajax, filters and shortcodes
- Widget area inside a widget
- Defer Code in Widgets – Page Speed
- Where are widget configurations stored?
- Bolding specific word(s)/parts of widget title
- How to add a class to a link in text editor
- WordPress widget new instance creates content duplicates
- Remove the widgets tab from theme customizer
- Remove/Add widgets from/to the Available Widgets pool
- Remove/Unregister or hide a widget added by a plugin
- Why are Shortcodes Disabled in Widgets by Default?
- How can I apply css styling to the current day in the calendar widget
- Warning: Missing argument 2 for widget_title filter
- How to check if a widget has no title
- Widget html code error
- How to add #navbar to all page links?
- How to truncate titles in Recent Posts widget?
- Can’t see widget areas in my customizer
- Widget textarea input gets formatted
- How to display/register widget only on post pages in custom plugin
- Fire on widgets_init only on dashboard
- Access Customizer widget instance form
- is_tax() not working in Widget Logic [closed]
- One register_sidebar function works, the other doesn’t?
- Modify WordPress widgets Screen
- What does apply_filters() do exactly? [duplicate]
- Portfolio Filter Buttons Wont Work
- Change Woocommerce Product Categories Widget ‘Title’ based on Product Category
- add_filter to the_content after apply_filters
- How to customize wordpress sidebar widget
- Jquery checkbox -show posts with checked tags
- Creating New Dynamic Fields for a Certificate (Number Generation, Code Referencing, and more)
- How to translate widget titles in 2021 theme?
- Mystery line break
- A checkbox Option for description in Widget
- Filter WordPress Archive Widget to exclude posts with specific custom taxonomy term id
- Handling dozens of sidebars
- apply_filters to $GLOBALS
- apply_filters to content but ignore shortcodes
- Inkness theme sidebar
- Automatically hide Widgets that would lengthen page
- Add New Footer Widget Area with Limited Options?
- Database size Widget
- How to inject a virtual widget (i.e. without adding it to the database) to the sidebar
- SVG Icon Code Support in WordPress Custom Html Widget? Not Working
- Remove nofollow attribute from social widget links
- Create custom dashboard for plugin
- Why doesn’t my star rating widget work?