4

When I upload an image, it is automatically resized as I would expect, however the sizes for inserting the image seem to ignore the settings I've placed in Settings/Media.

In my media settings I have:

  • Thumbnail: 150 x 150
  • Medium: 300 x 300
  • Large: 690 x 9999

I upload an image of: 2226 x 1663.
Wordpress generates the correct image sizes, but gives me the following options for insertion:

  • Thumbnail: 150 x 150 (as expected)
  • Medium: 300 x 224 (as expected)
  • Large: 640 x 447 (Wrong. Why?)

I looked on the forums and found a suggestion that I add the following to my functions.php file:

update_option('large_size_w', 690);

However, this did not work.

9
  • On further investigation, it appears Wordpress is resizing the image correctly, to 690 x 515 - however it is still inserting the image at 640 x 447 using the width and height parameters of the IMG tag.
    – Gary
    Commented Apr 5, 2012 at 13:08
  • Can you please edit your question to revise the title and description to reflect this discovery? Commented Apr 5, 2012 at 13:51
  • Also: What Theme is currently active. (If not Twenty Eleven, please switch to Twenty Eleven, regenerate Thumbnails if necessary, and verify if you still observe the same behavior.) And do you have any Plugins active that interact with image functionality? Commented Apr 5, 2012 at 13:53
  • I switched this to Twenty Eleven and the sizes were all different. Presumably then, something in my theme (or more likely, the base theme on which it is running, since mine is a child theme of the 'Boilerplate' theme) is setting the large image to 640. Does anyone know what setting I would be searching for to find this?
    – Gary
    Commented Apr 5, 2012 at 14:42
  • Which "Boilerplate" Theme are you using (there are more than one). Can you link to it, so we can have a poke around? Commented Apr 5, 2012 at 15:58

3 Answers 3

8

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.

The solution, then, if you need to change the large image width to 690px (and assuming your Child Theme can accommodate this width), is to define $content_width in your Child Theme functions.php file. I would recommend using a Child Theme setup function, hooked into after_setup_theme(), like so:

<?php
function wpse48075_theme_setup() {
    // Define $content_width global
    global $content_width;
    if ( ! isset( $content_width ) ) {
        $content_width = 690;
    }
}
add_action( 'after_setup_theme', 'wpse48075_theme_setup', 9 );
?>

The priority 9 is probably overkill, since your Child Theme's actions will be added before the parent Theme's actions anyway; but using priority 9 will guarantee that this action fires before the parent Theme setup fires, at priority 10.

Since your Child Theme action fires first, the Child Theme defines $content_width, and the Parent Theme does not override it (since it also uses a if ( ! isset() ) conditional wrapper).

Edit

So, looking at the Twenty Eleven functions.php file, I realized I made a bad assumption: Twenty Eleven defines $content_width nakedly in functions.php, rather than inside the Theme setup function, hooked into after_setup_theme. So, to override it, ** you have to do likewise**.

Just put the following at the top of your functions.php file, before any other function definitions:

$content_width = 690;

This should work, since the Child Theme functions.php gets parsed before the Parent Theme functions.php.

(This is a prime example of why Themes should wrap all the things inside callbacks. :) )

6
  • Excellent, thanks for your help. I'll give that a try.
    – Gary
    Commented Apr 5, 2012 at 20:40
  • Unfortunately, this didn't work either... I don't know enough about Wordpress really offer any suggestions as to why, this looked like it would work fine. Any ideas?
    – Gary
    Commented Apr 12, 2012 at 9:27
  • You never answered my question above: "And let me guess: in Twenty Eleven, the Large image size is constrained to a width of 584px?" Is that the case? Commented Apr 12, 2012 at 12:33
  • It is, yes... That's why I thought your suggestion would work! ;)
    – Gary
    Commented Apr 12, 2012 at 16:24
  • See updated answer. :) Commented Apr 12, 2012 at 18:13
0

Modify your settings on the media page so that your maximum embed width is 690 rather than blank

enter image description here

1
  • I've already done this to no avail.
    – Gary
    Commented Apr 5, 2012 at 14:35
0

If you want more control on what image sizes are generated when you upload images, have a look at the Simple Image Sizes plugin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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