Last active
August 29, 2015 14:01
-
-
Save LeEnno/f7f44a9f47046b466f1e to your computer and use it in GitHub Desktop.
Wordpress: wrap first image with `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
<?php | |
function supergeil_wrap_first_img_with_div($content) { | |
$pattern = '/<img ([^>]+) \/>/'; | |
$replacement = '<div class="supergeil"><img $1 /></div>'; | |
return preg_replace( $pattern, $replacement, $content, 1 ); | |
} | |
add_filter( 'the_content', 'supergeil_wrap_first_img_with_div' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment