Support » How-To and Troubleshooting » wp_get_attachment_image: Adding CSS Classes

wp_get_attachment_image: Adding CSS Classes

  • Hi folks. With the function wp_get_attachment_image I can get an image-attachment as html img element. The element has a CSS class of ‘attachment-$size’ ($size is replaced by the argument you call the function with).

    Now I want to add a CSS class to have something like <img class=”attachment-medium someclass”… />.

    I thought this could be done with wp_get_attachment_image( $attachment_id, $size, $icon, $attr=array('class' => 'someclass') )…But this replaces the default class ‘attachment-$size’ with ‘someclass’.

    It’s supposed to merge/append additional classes like the_post_thumbnail does, isn’t it? So is this a bug or is it the intended behavior of wp_get_attachment_image?

    @dear Moderator: Don’t know if this is the right forum for this question. If not, feel free to move it 🙂

  • The topic ‘wp_get_attachment_image: Adding CSS Classes’ is closed to new replies.