I am using wp_get_attachment_image_src to construct the srcset attribute of an img tag. In that attribute I want to output a comma separated list of image urls along with the image widths.

Using the Media Settings page, I have configured the image sizes to be as follows:

  • Thumbnail size: 150x150
  • Medium size: 640x480
  • Large size: 1024x768
  • Small size: 278x320

The wp_get_attachment_image_src function returns the correct urls and the correct widths for the image sizes full, medium and small. small is a custom size I added using add_image_size.

If I call wp_get_attachment_image_src( $image_id, 'large' ), the returned array looks like this:

array (
    0 => 'http://localhost/wp-content/uploads/2014/10/image-1024x768.jpg',
    1 => 640,
    2 => 480,
    3 => true,

Checking the image which can be found at that url turns up the image with the correct dimensions.

Currently i am using the php builtin function getimagesize to circumvent this problem, but this function call takes significantly longer than simply accessing the index returned by wp_get_attachment_image_src:

Without getimagesize (mtime before and after execution):

  • '0.83761000 1415195440'
  • '0.83831600 1415195440'

With getimagesize:

  • '0.34808000 1415195635'
  • '0.35323900 1415195635'

What can I do to make wp_get_attachment_image_src return the correct dimensions?

  • Do you have plugins installed or is this vanilla? If so could you edit your question and list the plugins?
    – Howdy_McGee
    Commented Nov 5, 2014 at 14:36
  • I am developing a theme which does not depend on any plugins. So no i don't have any plugins installed, this is a vanilla wordpress installation.
    – BdN3504
    Commented Nov 5, 2014 at 15:56
  • Under Settings -> Media did you uncheck the crop checkbox?
    – Howdy_McGee
    Commented Nov 5, 2014 at 16:12
  • There is no crop checkbox for the large size. Which crop checkbox are you referring to? The crop checkbox for the thumbnail has no effect on the large image as far as i know. I tried unchecking, there is no difference no matter if it's checked or not.
    – BdN3504
    Commented Nov 5, 2014 at 17:19

1 Answer 1


I found the same issue here and the solution from there works.

The solution is as simple as pasting this:

$content_width = 2000;// Value higher than your new 'large' width

in functions.php

Explanation copied from there(user Chip Bennett):

I believe your issue is that the value set for the global $content_width variable (which is 640px in Boilerplate and 584px in Twenty Eleven) is less than the width you're specifying via Settings -> Media.

WordPress is overriding your user setting with the Theme-specific value. This actually makes sense, since a Theme knows its maximum content width, and using a larger image width than what the Theme is designed to accommodate would very likely break the Theme layout.

Check the link above to refer to his full answer.

This is a link to the underscores theme project, where they set this value.

  • 1
    Rather flag a post as a duplicate that reposting an answer from another post. There is no problem is reposting someone else's answer as you did, but then you have to add a substantial amount of your own logic to that info to make it a legitimate free standing answer. Commented Nov 6, 2014 at 7:40
  • 2
    I was unaware there already was an answer to my problem. Thanks for helping and sorry for creating a duplicate, but I think some programmers might stumble upon this question more easily.
    – BdN3504
    Commented Nov 6, 2014 at 9:45
  • There also is a support page on Content Width and an article discussing its usefulness. In a fluid layout, this global has no purpose therefore I think it is ok to unset it.
    – BdN3504
    Commented Nov 6, 2014 at 9:53

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