Skip to content

Instantly share code, notes, and snippets.

@igoravl
Last active September 2, 2016 04:36
Show Gist options
  • Save igoravl/3d5b759a358986fa94494ccf5ac96e1f to your computer and use it in GitHub Desktop.
Save igoravl/3d5b759a358986fa94494ccf5ac96e1f to your computer and use it in GitHub Desktop.
<?php
function surround_img_tags_with_figure( $content )
{
$content = preg_replace(
'/<p>((<a.+?\>)?<img.*title=\"([^\\"]+)\".*?>(<\/a>)?)<\/p>/',
'<p><figure>$1<figcaption>$3</figcaption></figure>',
$content);
return $content;
}
add_filter( 'the_content', 'surround_img_tags_with_figure', 99 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment