Here is how I am calling wp_get_attachment_image:

$id = attachment_url_to_postid( get_theme_mod( 'blue_logo' ));
echo wp_get_attachment_image($id, $size = 'blue_logo', $icon = false, array(
   "class" => "blue_logo"

'blue_logo' size is referencing an image size that I am creating in functions.php. Here is what the output element looks like.

<img width="216" height="67" src="
content/uploads/2022/02/Q7_WHM_HOR_BLUE-1.jpg" class="blue_logo" alt="" loading="lazy" 
srcset=" 2062w, 300w, 1024w, 768w, 1536w, 2048w, 1568w" sizes="
(max-width: 216px) 100vw, 216px" style="width:100%;height:30.99%;max-width:2062px;">

I understand that I can override the styling with CSS, but when I do that it's causing some compression which is causing the image to lose quality. Is it possible to not have the inline styling at all in the first place? My ultimate goal here is to be able to display an image that is being uploaded via a custom WP_Customize_Image_Control and set the image size with as little image compression/loss in quality possible.

Thank you for the help!

1 Answer 1


You could try using get_attachment_image_url() instead. This will give you the url for the full image. You can

Call it like this:

echo '<img class="blue_logo" src="'.get_attachment_image_url($id, 'blue_logo').'">';
  • Thank you this worked out! In case anyone else stumbles upon this answer, if you notice the sizes not updating, you might need to completely remove the image from your media library and reupload with the new sizes applied. This stumped me for a while :)
    – BeccaN
    Feb 21, 2022 at 16:05
  • 1
    You could also use a plugin to regenerate thumbs or use wp-CLI to do it!
    – rudtek
    Feb 21, 2022 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.