Support

Account

Home Forums General Issues Removing Paragraph Tags Reply To: Removing Paragraph Tags

  • Hi @tebbott: Could you help me adapt this function? I want to apply it to a slightly different scenario, but my regex chops aren’t good enough:

    function filter_ptags_on_acf_images($acfcontent){
    		return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(\/a>)?\s*<\/p>/iU', '\1\2\3', $acfcontent);
    	}
    	add_filter('acf_the_content', 'filter_ptags_on_images');

    Function output:

    <a href="#"><div>
    </div></a>

    Generated markup:

    <a href="#"><div>
    </div><p></a>

    How can I strip out that annoying p tag?

    I’m also using a version of the wpex_clean_shortcodes() function listed above. It works well for some scenarios but it’s not helpful here. Can your regex function help me?