Settings in ‘Media > Settings’ is ignored when inserting images

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.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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. 🙂 )

Method 2

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

enter image description here

Method 3

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x