Forked from hagronnestad/WordPress: Wrap images in DIV.php
Created
February 22, 2017 22:24
-
-
Save laurent-d/0e98f544b33e82a52cd6508f22ec47a4 to your computer and use it in GitHub Desktop.
WordPress: Wrap images in DIV.
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
// ======================= | |
// = 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