Skip to Content


Limit the requested image to a max size to prevent huge filesize images from loading on the front-end.

PHP April 9, 2019


This function runs automatically, so it is not called manually. Is this incorrect?


Serving images with a max width of 1200px.



Additional Notes

Original size of this test image is 7360×4545.

This image is loaded via the WYSIWYG editor from the media library.

When this will not control output image sizes:

This function listens for full sizes to be used and limits them. Therefore there are plenty of situations where this will not limit output image sizes.

  • If the Nebula Option “Limit Image Dimensions” is disabled (which it is by default)
  • When specified image sizes are added and used
  • If an image is hard-coded into a template file or stylesheet
  • Inside galleries
  • This may not work inside third-party plugins
  • (Possibly others too)

Here is another test using the WordPress Block Editor.

Was this page helpful? Yes No

    A feedback message is required to submit this form.

    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

    Located in /libs/Optimization.php on line 125.

    No Hooks

    This function does not have any filters or actions available. Request one?
            public function limit_image_size($size, $id=false){
                if ( $this->get_option('limit_image_dimensions') ){
                    if ( is_string($size) && ($size === 'post-thumbnail' || $size === 'full') ){
                        if ( $this->is_save_data() ){
                            return 'max_size_less';
                        return 'max_size';
                return $size;


    This function can not be short-circuited with an override filter. Request one?