TinyMCE strips breaks inside editor
TinyMCE strips breaks inside editor
TinyMCE strips breaks inside editor
Removing line breaks when in text view with wp_editor
wpautop is not working when displaying content saved using wp_editor in a custom meta box
Removing “wpautop” (auto tags) only on certain pages?
Try this: // replaces [banner …] .. [/banner] with <!–banner ID–> before the_content filters run add_filter(‘the_content’, ‘protect_my_shortcode’, -100); function protect_my_shortcode($content){ return preg_replace_callback(‘/\[(banner)\b(.*?)(?:(\/))?\](.+?)\[\/\1\]/s’, ‘protect_my_shortcode_callback’, $content); } function protect_my_shortcode_callback($matches){ global $__banners; $id = ‘<!–banner ‘.count($__banners).’–>’; $__banners[$id] = do_shortcode($matches[0]); // or ‘[‘.$matches[1].’ ‘.$matches[2].’]’.$matches[4].'[/’.$matches[1].’]’ // if you need to run any filters on the shortcode content ($matches[4]) return $id; … Read more
This error was corrected when I installed the plugin TinyMCE Advanced and activated the option “Stop removing the <p> and <br /> tags when saving …”.
Ok if you want to strip the p tags for img’s and iframe’s for advanced custom fields you have to exchange the_content with acf_the_content . The code looks that way: function filter_ptags_on_images($content) { $content = preg_replace(‘/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU’, ‘\1\2\3’, $content); return preg_replace(‘/<p>\s*(<iframe .*>*.<\/iframe>)\s*<\/p>/iU’, ‘\1’, $content); } add_filter(‘acf_the_content’, ‘filter_ptags_on_images’);
Try this function out, be sure to add your shortcode in the array // (OPT) STOP SHORTCODES THAT DON’T USE INLINE CONTENT FROM BEING WRAPPED IN A P TAG (until WP fixes this) // ** NOTE -> BE SURE TO change the array to the shortcodes you are using! add_filter(‘the_content’, ‘the_content_filter’); function the_content_filter($content) { // … Read more
gdaniel answered the bulk of question with this comment: Every time you type Enter (the return character) the editor creates a new paragraph <p>my content</p>, the alternative is to type Shift+Enter so that the editor creates a line break (<br/>) instead. Note that the the <br /> and </p> tags are added via wpautop, one … Read more
OK, it seems someone has trod this path and there is in fact…. shortcode_unautop() Job Done. It looks elegant in the editor and works in the output. The shortcode now looks like this; function column_shortcode($atts = [], $content = null) { $content=”<div class=”two-column”>”.$content.'</div>’; $content = shortcode_unautop($content); return $content; } add_shortcode(‘two-column’, ‘column_shortcode’);