Add Max Width to WordPress Image Uploads

The core WordPress media manager does a pretty good job of helping folks to automatically manage their images. Depending on your setup, WordPress will look for the GD Image Library on the server (you can also set it to ImageMagick if you prefer…like I do) and resize your images, auto-create thumbnails, and perform other neat on-the-fly chores that would take awhile to do if you blog a lot.

The later versions of WordPress will take a large image and create 4 different images once you upload it: a thumbnail, small, medium, and large, along with the original. You can then select which image you would like to insert into your post.

Over the past two weeks, I’ve been helping my Mother move from a Blogger blog to a new WordPress blog. She had been wanting the ability to have a wider “content” area and wanted a fresh new look. So, we found her a template that would work well for her and I modified it to fit her needs.

One of the issues we had, once we launched her new blog was image sizing. Sometimes she’ll upload images from her digital camera (which are really large) and other times she’ll grab smaller images from a Google search to include in her posts. It was confusing to her to not have all the size options each time she uploaded an image. See, if a photo is relatively small when you upload it, you won’t get the options for a small or medium image, only the original. Conversely, if a very large image is uploaded and she chooses ‘large’ or ‘orginal’ it may be too wide for the content area and essentially ‘break’ the layout.

Fortunately, there is a simple solution. Locate your theme’s main functions.php file (typically found in the theme’s root directory), and add the following after the opening < ?php:

$GLOBALS['content_width'] = 800;

This will set the maximum width for uploaded images to 800 pixels. You may, of course, adjust as necessary. Now, when my Mom uploads an image, she always knows to choose the ‘original’ option, because it will never be ‘too large’ for the content wrapper…of course, she doesn’t know that this piece of code is in place…she just knows that it works. And, as they say, ignorance is bliss.

Leave a Reply

Your email address will not be published. Required fields are marked *