1) Filter wpautop() with ACF:
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\');
add_filter(\'the_content\', \'filter_ptags_on_images\');
如果两者都有,请尝试在add\\u筛选器上使用稍后的优先级进行检查。有可能主题、插件或acf正在覆盖您。。。。
add_filter(\'acf_the_content\', \'filter_ptags_on_images\', 9999);
add_filter(\'the_content\', \'filter_ptags_on_images\', 9999);
2) Edit wpautop():
<?php
remove_filter( \'the_content\', \'wpautop\' );
add_filter( \'the_content\', \'custom_wpautop\' );
function custom_wpautop() {
// copy wpautop() code at https://core.trac.wordpress.org/browser/tags/4.2.2/src/wp-includes/formatting.php#L373 and add img to the $allblocks variable
}
3) This above is a lot of code for one task however. Consider trying this:https://wordpress.org/plugins/preserved-html-editor-markup-plus4) You could try this although not as good as the method you\'re trying to accomplish since this one is done with javascript.
<script type="text/javascript">
jQuery(document).ready(function($){
$(\'p > img\').unwrap();
});
</script>
5) if it\'s just the styling that\'s messing things up and you don\'t care about the markup:
<style type="text/css">
p > img {
margin: 0 !important;
}
</style>