Skip to content

Instantly share code, notes, and snippets.

@Soullighter
Created February 21, 2023 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Soullighter/1269939ec022baa0eed45502c73c902d to your computer and use it in GitHub Desktop.
Save Soullighter/1269939ec022baa0eed45502c73c902d to your computer and use it in GitHub Desktop.
Remove <p> Paragraph around <img> image in Advanced Custom Field ( ACF ) WYSIWYG editor
<?php
// In this example we are adding <div> with class Figure around <img>
// If you want to remove <div> just simple delete open/close tag and leave $1 between ''
function img_unautop($pee) {
$pee = preg_replace('/<p>\\s*?(<a .*?><img.*?><\\/a>|<img.*?>)?\\s*<\\/p>/s', '<div class="figure">$1</div>', $pee);
return $pee;
}
add_filter( 'acf_the_content', 'img_unautop', 30 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment