How the variable content_width constrains the size of inserted images in WordPress

The article describes how images are constrained in size when inserted in the editor in WordPress, and the role of the variable $content_width. Under certain conditions even thumbnails and medium-sized images are constrained.

In the recent release of WordPress 3.5, one the most noticeable changes is the total overhaul of the media management, including media upload, media insertion and creation of galleries.

I was lucky to be able to make a small contribution to this release, specifically I helped to get the correct display of dimensions for large-size images in the size drop-down list in the sidebar of the Insert Media panel.

In this post I will describe the behind-the-scenes working of how images sometimes are constrained in size when added to a post. By constrained is meant that their height and width attributes are reduced compared to the actual image size. This is generally done to make the images fit in the main content area of the post.

A constrained large-size image
A large-size image constrained to 704px, and with a max-width of 100%

Read more »