Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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