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
- AAPF Filter group is not in widget section
- Extending the WordPress Recent Posts Widget
- WordPress 5.8 : display new widget
- delete widget upon uninstall
- Determine if a specific Gutenberg block is used on pages/posts
- Can I add Short Code Of A Plugin In The Code Editor of WordPress?
- Use atributes of shortcode in get template part
- the_content getting current page content instead specified ID
- Add filter for specific category only
- WordPress 5.8 Beta 3 Widget Block: widget_id is undefined when a widget is placed
- Customizing the wp_video_shortcode output with add_filter
- Your theme has 8 widget areas, but this particular page doesn’t display them
- How to use register_sidebar’s ‘before_widget’ unique id generator into its other parameters like ‘before_title’?
- A message to clients in the dashboard widget received from another site
- Set a dashboard widget to the top?
- Display Most Recent Post Widget Title On Page
- Fatal error: Uncaught Error: Class ‘WP_Widget’ not found
- Array showing all values of loop instead of specific value to post
- How to paste widget to a specific page
- How can I remove WordPress element IDs and Class names in the HTML?
- Disable wpautop on Shortcode attributes
- Remove widgets on mobile front page without affecting desktop
- Dynamic Bootstrap Carousel ID per widget on same page
- How to get individual values from custom widget?
- Shortcodes not processing inside post content
- How would you return a value from an individual field in a custom widget?
- Need to delete the sidebar widget area and have the page a full page rather than just have a blank widget area
- How to decorate WP_Widget_Text?
- How do I find out which
- Widget not appearing in customizer
- After adding widget the style is messing up
- How do I get my custom widget to show on live site?
- Override wordpress audio playlist
- Mobile view: how to remove right/left margin from the specific widgets?
- Unable to see Widget Submenu under Appearance with Class Based WP_Widget
- Widget display nothing
- How can I add a widget area to the top of the Dashboard?
- I want to hide “sold by” on certain pages with id page 43
- Tabs widget from Elementor is not showing the content in it to users. But at admin side it is working fine
- How to update a widget data?
- How can I have sidebar widgets on Twenty Seventeen theme on all pages?
- Mystery line break
- why the code html apear in this widget in footer
- Widgets are not displaying in my theme
- An archive widget, coming from nowhere on my posts and pages
- how to make video autoplay in widget
- Widget title showing below widget
- Changing Date Format on Custom Meta Data w/shortcode call
- Archive Widget – Count only parent posts
- Elementor or WordPress randomly adds the word “array” to my custom widget
- Widget form not displaying for media widgets in WordPress
- Display Login user name in Thim:login Popup widget
- How to wrap pattern-matches from the_content in [wiki]-shortcode tags
- Reload page with a different shortcode when a user selects from a dropdown
- Searching for a one page overview widget
- Sorting Tag Cloud by Popularity
- custom widget not saved to sidebar