Skip to content

Instantly share code, notes, and snippets.

@LeEnno
Last active August 29, 2015 14:01
Show Gist options
  • Save LeEnno/f7f44a9f47046b466f1e to your computer and use it in GitHub Desktop.
Save LeEnno/f7f44a9f47046b466f1e to your computer and use it in GitHub Desktop.
Wordpress: wrap first image with `div`
<?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