[wp-trac] [WordPress Trac] #30180: wp_get_attachment_image_src does not return alt or meta
WordPress Trac
noreply at wordpress.org
Sun Jan 27 22:47:56 UTC 2019
#30180: wp_get_attachment_image_src does not return alt or meta
--------------------------------------+-----------------------------
Reporter: joedolson | Owner: joedolson
Type: enhancement | Status: accepted
Priority: normal | Milestone: Future Release
Component: Media | Version:
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests | Focuses: accessibility
--------------------------------------+-----------------------------
Comment (by ryanshoover):
The existing `wp_get_attachment_image_src` fucntion is oddly named as it
returns 4 different values, only one of which corresponds to the function
name.
The mindset with the new `wp_get_attachment_image_attr` is that it's a
single function that can retrieve a number of relevant image attributes.
Rather than continue to "tweak" a function that should be renamed, themers
can now call `wp_get_attachment_image_attr( $attachment_id, 'alt' );` to
get the image alt tag. If the themer wants to do more complex creation of
an image tag, `wp_get_attachment_image_attr( $attachment_id );` will
return all attributes needed to create a full `<img>` tag.
{{{
$attrs = wp_get_attachment_attr( $attachment_id );
// Echo the image.
?>
<img
src="<?php echo esc_url( $attrs['src'] ); ?>"
alt="<?php echo esc_attr( $attrs['alt'] ); ?>"
class="<?php echo esc_attr( $attrs['class'] ); ?>"
width="<?php echo esc_attr( $attrs['width'] ); ?>"
height="<?php echo esc_attr( $attrs['height'] ); ?>"
srcset="<?php echo esc_attr( $attrs['srcset'] ); ?>"
sizes="<?php echo esc_attr( $attrs['sizes'] ); ?>"
>
<?php
}}}
Can I propose that we accept this patch adding a new function? Or do I
have clear direction to rework `wp_get_attachment_image_src` to also
return the alt attribute as a 5th element in an indexed array?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/30180#comment:33>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list