Created
February 21, 2023 14:32
-
-
Save stefanRepac/1269939ec022baa0eed45502c73c902d to your computer and use it in GitHub Desktop.
Remove <p> Paragraph around <img> image in Advanced Custom Field ( ACF ) WYSIWYG editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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