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
- How Can I Add the “Insert From URL” Tab to a Custom 3.5 Media Uploader?
- Where is the content of widgets stored in mysql table
- How do I rebind event after widget save
- Determining a Widget Instance and Sidebar Location?
- Where to get the unsaved list of widgets in customizer?
- Widget Update Code Not Working
- Is It Possible to Restore Accidentally Deleted Widgets?
- Using tabs in admin widgets [closed]
- Widget “Save” resetting jQuery hidden fields
- Create variable from widget instance
- Save/update widget outside admin panel [closed]
- Why use widgets?
- Completely disabling widgets
- Creating your own widgets: using cache?
- How does the default recent posts widget work with cache?
- Add new section to “Right Now” widget
- gutenberg widget outputting paragraph marks
- How to disable Widget Gutenberg Blocks?
- Replace dashboard widgets with banner ad
- Too few arguments to function WP_Widget::__construct(),
- instance is empty in function widget()
- Check which registered sidebar a widget is added to
- Too many widgets
- Why can’t I see “Widgets” in my Apperance menu?
- Image Uploader API
- Wrap the widget content with a div and get the widget title outside? [closed]
- add widget to page content (using shortcode)
- Custom tag being removed from text editor
- Programmatically add widgets to sidebars
- How to create a dashboard widget for one user
- Programmatically add widgets to sidebars
- How to activate WordPress widgets but not display?
- WordPress archives widget causes Bing bot 404 errors
- Enqueue script only when side widget is used
- Check if widget is inside sidebar with PHP
- Modify a plugin function output from another plugin
- Widget : html 2 dimensional array doesn’t work
- Widget constructor: about $id_base and $options
- Disable wpautop on Shortcode attributes
- Shortcodes not processing inside post content
- I want to hide “sold by” on certain pages with id page 43
- Display Login user name in Thim:login Popup widget
- WP renders HTML wrong when adding widgets
- How do I add after the tag in WordPress widget?
- Reposition the widget sidebar in Appearance->Widgets
- Hiding the widget meta box in the Appearance->Widget screen
- The WP_Widget class seems to run many times on a page load
- Shortcode to eliminate and replace with
- How to call theme default widget in custom template?
- How can I build a widget area widget using the built in WordPress functionalities?
- Widget Logic code for different PMP membership levels
- How to display a widget available for all themes
- widgets in contacts only
- How can I display wp_link_pages before a shortcode, if it is used, or display after content?
- How to create a widget on witch a registered user can create a checklist
- Can I prevent wordpress adding and tags to autoembeds
- Custom dashboard widget – load style only for added widget