Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

If I upload a large size image inn my wordpress, the image breaks my template width. I have seen some templates which scale the large image's width to the maximum width of the post div. What CSS or code I need to change for that purpose? Thanks.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

In your functions.php file, you need to define $content_width, which will cause WordPress to scale large-size images, and also embedded videos, accordingly.

e.g. if the width of your content area is 600px:

if ( ! isset( $content_width ) ) {
    $content_width = 600;
}

You will probably also want to add accompanying CSS, e.g.:

#content img {
    width: auto;
    max-width: 600px;
    height: auto;
}

That way, when the image is scaled, it will maintain its proportion; rather than merely having its width reduced, the height will also be scaled proportionately.

share|improve this answer
add comment

You don't need any CSS, just go to Settings > Media and adjust the Large image size width to that of your post container. You may need to Regenerate Thumbnails after doing that.

share|improve this answer
add comment

Your Answer

 
discard

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

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