souporserious
souporserious

Reputation: 2157

Remove wp_get_attachment_image Image Size

Is there any way to remove the image size of the wp_get_attachment function?

I was trying the following code with no luck, trying to get it either 100% or nothing at all.

echo wp_get_attachment_image($variable, array(100 . '%', 100 . '%'));

EDIT

This is what I ended up with that works perfectly thanks to drew010.

echo '<img src="'.wp_get_attachment_url($variable).'" alt="'.get_the_title().'" />';

Upvotes: 3

Views: 4151

Answers (3)

bernard
bernard

Reputation: 21

You can't use it this way: alt="'.get_the_title().'"

You must use esc_attr($attachment->post_title) or the_title_attribute().

If the title has some html tags your alt attribute can crash your html outline. Trust me, a year ago I searched for over 1 hour this bug in some theme.

Upvotes: 0

drew010
drew010

Reputation: 69937

@Jrod has the correct answer IMO, but you can also just call

wp_get_attachment_url($variable);

which gives you the URL to the full image. Then you can simply construct your own HTML markup for displaying the image.

Upvotes: 3

Jared
Jared

Reputation: 12524

If you want the full size image you should use the following:

echo wp_get_attachment_image($variable, 'full');

Upvotes: 1

Related Questions