WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing a theme that has a max body width of 620px. I've set $content_width to 620 in functions.php, as well as included the following code in my style.css file following the Codex page on content_width

.size-thumbnail {
    max-width: 100%; 
    height: auto; 

However, when I tested this by creating a new post with an image of width 1290px, the image still appeared in full size, instead of respecting the content width set. When I inspected the HTML generated I found this:

<div class="wp-caption alignnone" style="width: 1290px">
    <img alt="" src="..." width="1280" height="720" />
    <p class="wp-caption-text">...</p>

which suggests that either the code in the documentation is outdated, or I must be missing some option to reduce the image dimensions down without having to modify the post?

share|improve this question
Are you using one of the wordpress default themes twenty-x? or a another custom theme, image sizes can be defined in functions.php using add_image_size( "imagetype", 232, 150, true ). The theme needs to be built to know to use a defined size when rendering the front end though. – Matt.C Sep 18 '13 at 7:44
@Matt.C I've already defined the image sizes in the theme's functions.php file. In the test post I didn't choose any of the sizes when I added the image because I expected WordPress to automatically reduce images that are too large down to the size set in $content_width, but that didn't happen – Yi Jiang Sep 18 '13 at 8:25
$content_width affects the "large" image size, try setting your theme to use "large" for the image and $content_width should work – Matt.C Sep 18 '13 at 8:32
@Matt.C How would I be able to do that? I can set the size for the featured image, but I found no documentation about setting the size of images in posts added there by users through the theme – Yi Jiang Sep 18 '13 at 10:55
have you tried selecting "large" when inputting an image? I think (although I could be wrong) that this is just he way $content_width works, it affects the images that have a size selected, by not selecting a size, wordpress uses the original file, and ignores $content_width – Matt.C Sep 18 '13 at 10:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.