Skip to content

Instantly share code, notes, and snippets.

@roborourke
Last active August 29, 2015 14:03
Show Gist options
  • Save roborourke/05c105d53fe6680a9e2e to your computer and use it in GitHub Desktop.
Save roborourke/05c105d53fe6680a9e2e to your computer and use it in GitHub Desktop.
Magical unautopeerer
<?php
// unautop function for embed/images etc... with alignminet classes
add_filter( 'the_content', function( $pee ) {
$pee = preg_replace( '/<p>\s*((?:<a [^>]*?>)?<(img|iframe|object|embed) [^>]*?(\balign[a-z]+\b)? (?:[^>]*?)>(?:.*?<\/\2>)?(?:<\\/a>)?){1}\s*<\\/p>/sm', '<div class="media media-$2 $3">$1</div>', $pee );
return $pee;
}, 11 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment