grantsmith
Member
- Local time
- 21:46
- Joined
- Aug 2, 2020
- Messages
- 16
I'm currently developing my first WordPress theme and all is going fine. However, I seem to be struggling with outputting attributes of images from the media library. This seems really over complicated?
I finally worked out the alt attribute…
PHP:
<?php
$thumb_id = get_post_thumbnail_id(get_the_ID());
$alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true);
if(count($alt)) echo $alt;
?>
alt="<?php echo $alt; ?>"
Although it feels very cumbersome but works. As for the width and height attributes I'm lost :)
Am I approaching this all wrong?
I just want to output alt, width and height!