I’ve this code which provides peak and width information for photos in posts and pages:
operate add_img_size($content material){
$sample = '/<img [^>]*?src="(https?://[^"]+?)"[^>]*?>/iu';
preg_match_all($sample, $content material, $imgs);
foreach ( $imgs[0] as $i => $img ) {
if ( false !== strpos( $img, 'width=" ) && false !== strpos( $img, "peak=" ) ) {
proceed;
}
$img_url = $imgs[1][$i];
$img_size = @getimagesize( $img_url );
if ( false === $img_size ) {
proceed;
}
$replaced_img = str_replace( "<img ', '<img ' . $img_size[3] . ' ', $imgs[0][$i] );
$content material = str_replace( $img, $replaced_img, $content material );
}
return $content material;
}
add_filter('the_content','add_img_size');
Nevertheless, this code doesn’t add in peak and width information for any photos which can be current in tag descriptions or class descriptions.
Query: how can I edit this code in order that tag descriptions and class descriptions are additionally included within the filter/operate above and pictures in tag/class descriptions have peak and width information added routinely?
Thanks.