Skip to content

Instantly share code, notes, and snippets.

@brunomonteiro3
Created December 7, 2016 23:44
Show Gist options
  • Save brunomonteiro3/56ef7a3d1329de68f27614227a0308f5 to your computer and use it in GitHub Desktop.
Save brunomonteiro3/56ef7a3d1329de68f27614227a0308f5 to your computer and use it in GitHub Desktop.
Add class to every image inside a <p> on the_content
<?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