[wp-trac] [WordPress Trac] #36996: get_the_post_thumbnail and the usage of class attribute
WordPress Trac
noreply at wordpress.org
Sat Jul 2 13:16:35 UTC 2016
#36996: get_the_post_thumbnail and the usage of class attribute
--------------------------+------------------------------
Reporter: TomasM | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 4.5.2
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Comment (by wido):
Your problem is inside the get_attachment_image function where the default
arguments ( class includes ) are parsed with the ones you provide.
{{{
// wp-includes/media.php:811 ( trunk )
$default_attr = array(
'src' => $src,
'class' => "attachment-$size_class
size-$size_class",
'alt' => trim(strip_tags(
get_post_meta($attachment_id, '_wp_attachment_image_alt', true) )), // Use
Alt field first
);
}}}
then
{{{
// wp-includes/media.php:821 ( trunk )
$attr = wp_parse_args( $attr, $default_attr );
}}}
The wp_parse_args use an array_merge where the $default_attr is the first
parameter and the second is $attr, so, the second parameter override the
first one.
I don't know if this is a bug or not, but you can use the
'wp_get_attachment_image_attributes' filter which will pass $attr,
$attachment and $size to add again the classes.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/36996#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list