Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save laurent-d/0e98f544b33e82a52cd6508f22ec47a4 to your computer and use it in GitHub Desktop.
Save laurent-d/0e98f544b33e82a52cd6508f22ec47a4 to your computer and use it in GitHub Desktop.
WordPress: Wrap images in DIV.
// =======================
// = WRAP IMAGES IN DIVS =
// =======================
function wrapImagesInDiv($content) {
$pattern = '/(<img[^>]*class=\"([^>]*?)\"[^>]*>)/i';
$replacement = '<div class="image-container $2">$1</div>';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
add_filter('the_content', 'wrapImagesInDiv');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment