WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#19013 closed defect (bug) (invalid)

wp_get_attachment_image not working as expected

Reported by: ramaboo Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords: reporter-feedback
Focuses: Cc:

Description

Assume the following bit of code:

wp_get_attachment_image(1, 'thumbnail', false, array('title' => 'fobar'));

It will produce something like this:
<img width="150" height="150" src="http://testcrave.genome.ramaboo.com/wp-content/uploads/2011/10/DC040811-RW23-150x150.jpg" class="attachment-thumbnail" alt="DC040811 RW23 150x150 gallery" title="foobar" />

as expected!

Now try this:
wp_get_attachment_image(1, 'thumbnail', false, array('alt' => 'fobar'));

and the result is:
<img width="150" height="150" src="http://testcrave.genome.ramaboo.com/wp-content/uploads/2011/10/DC040811-RW23-150x150.jpg" class="attachment-thumbnail" alt="DC040811 RW23 150x150 gallery" title="DC040811-RW23" />

I would expect it to honor the alt attribute but instead the system uses the default alt attribute. According to the documentation http://codex.wordpress.org/Function_Reference/wp_get_attachment_image passing in array('alt' => 'foobar') for $attr should be valid.

I also tried it with array('class' => 'foobar') and array('foo' => 'foobar') and both worked as expected. The only one I have found that does not work is array('alt' => 'foobar').

David

Change History (4)

comment:1 @SergeyBiryukov4 years ago

  • Keywords reporter-feedback added

I've checked this on 3.2.1 and 3.3-beta2, and the alt attribute is changed accordingly.

comment:2 @SergeyBiryukov4 years ago

Could you please provide steps to reproduce this on a clean install?

comment:3 @ramaboo4 years ago

You correct it works on a vanilla install. Must have been a plugin that somehow messed it up because it's not working on the live site I have.

comment:4 @SergeyBiryukov4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.