WordPress wpautop/shortcode generating invalid markup

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

How to remove p tags around img and iframe tags in the acf wysiwyg field

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’);

Extra paragraph tags in an enclosing shortcode

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’);

Disable formatting on textarea

Add a priority to push your function to the end of the hook queue. add_action(‘the_content’, ‘my_plugin_content_hook’, 1000); Then, in your get_special_content function you will need to apply wpautop manually to the content to which you want it applied. function get_special_content() { $text=””; $autopeed = ‘content to autop’; $text .= apply_filters(‘wpautop’,$autopeed); $text .= “your textarea code”; … Read more