Created
December 7, 2016 23:44
-
-
Save brunomonteiro3/56ef7a3d1329de68f27614227a0308f5 to your computer and use it in GitHub Desktop.
Add class to every image inside a <p> on the_content
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 | |
add_filter( 'the_content', 'img_p_class_content_filter', 20); | |
function img_p_class_content_filter($content) { | |
$content = preg_replace("/(<p[^>]*)(\>.*)(\<img.*)(<\/p>)/im", "\$1 class='content-img-wrap'\$2\$3\$4", $content); | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment