<div><img src="" alt=""></div>
Или как добавить class в ссылку на изображение?
<a href=""></a>
<a class="yourclass" href=""></a>
<a href=""><img class="wp-image-17300 size-full" src=""></a>
<div class="myphoto"><a href=""><img class="wp-image-17300 size-full" src=""></a></div>
function breezer_addDivToImage( $content ) {
// A regular expression of what to look for.
$pattern = '/(<img([^>]*)>)/i';
// What to replace it with. $1 refers to the content in the first 'capture group', in parentheses above
$replacement = '<div class="myphoto">$1</div>';
// run preg_replace() on the $content
$content = preg_replace( $pattern, $replacement, $content );
// return the processed content
return $content;
}
add_filter( 'the_content', 'breezer_addDivToImage' );
add_action('wp_footer', function(){
?>
<script>
document.addEventListener('DOMContentLoaded', function(event) {
jQuery(function($){
$('article img').wrap('<div class="myphoto"></div>');
});
});
</script>
<?php
});