Skip directly to the solution

If you want to skip all the explanation and go right to the solution, then click the above link.

I have a WordPress instance that I'm using to aggregate articles from RSS feeds with the CyberSyn plugin. 

Something that I noticed was that the wp-content/uploads directory was filling up quickly with images. These were not just the images from the feeds, but the resized images that Wordpress automatically generates. For every image that was in the wp-content/uploads directory, there were also about 8 other resized versions. And this was quickly taking up too much disk space.

I needed to stop this because I only want to store the original image. 

I learned that some of these images were being created as a result of using the MH Magazine lite theme. Disabling the theme would stop that theme from causing wordpress to generate images, but I looked for a way to stop the theme from making more images. I couldn't find an obvious way to prevent the theme from creating resized images without editing the theme's functions.php file, so I just disabled the theme entirely and I activated the default Wordpress Theme called "Twenty Seventeen". 

But then I noticed that Wordpress by default automatically generates several resized images for images stored in the uploads directory. Those images are in addition to those created by the ones created by whatever theme is installed.

So using the advice found at WPBeginner, I went to Settings -> Media in the WordPress dashboard and I set all of the image dimensions there to "0".

Now, when CyberSyn imported the images with the RSS feeds, I saw that some of the images - those specified in Settings -> Media - were not create. But there were still two images created by the Twenty Seventeen theme. 

I found that in order to keep the Twenty Seventeen theme from generating those images, I had to edit the functions.php file of the theme and comment out the following lines (lines 54 & 56):

 

    add_image_size( 'twentyseventeen-featured-image', 2000, 1200, true );

    add_image_size( 'twentyseventeen-thumbnail-avatar', 100, 100, true );

 

I ran another import of RSS feeds. And the two images that were being created with the code above were not being created after I commented out the code. 

But WordPress was still creating one extra image - the "medium_large" image. 

I haven't found a very elegant solution to prevent WordPress from making this image, but I did what I could. I found an answer in a StackExchange thread that showed a one line solution to get rid of the medium_large image.

I added the following to the bottom of the  functions.php file of the Twenty Seventeen theme:

 

/** 
 *  Stop making the medium_large image
 */
 
add_filter( 'wp_calculate_image_srcset', '__return_false' );
 

 

After saving that change, I ran another RSS import to create some new Wordpress Posts. Apparantly, putting the above code at the bottom of my functions.php file did nothing. The medium_large image was still being created.

What I found did work was adding the following to the functions.php file:

/**
 * Stop generating medium_large image
 */
function add_image_insert_override( $sizes ){
    unset( $sizes[ 'thumbnail' ]);
    unset( $sizes[ 'medium' ]);
    unset( $sizes[ 'medium_large' ] );
    unset( $sizes[ 'large' ]);
    unset( $sizes[ 'full' ] );
    return $sizes;
}
add_filter( 'intermediate_image_sizes_advanced', 'add_image_insert_override' );
 

I put that on the bottom of my functions.php file, then loaded up some more posts, and finally, WordPress didn't create the medium_large image anymore!

 

 

So here is exactly what I did to make WordPress not create any extra resized images

1. I switched to the "Twenty Seventeen" theme

The theme I was using was creating even more resized images than a default Wordpress install would create. So I switched to the default Wordpress theme.

2. Set all image dimensions to 0 in Settings->Media

I just went to Settings->Media and changed every number in the boxes to "0". 

3. Commented out the add_image_size lines from functions.php

I looked for the following two lines in functions.php and commented them out:

    add_image_size( 'twentyseventeen-featured-image', 2000, 1200, true );

    add_image_size( 'twentyseventeen-thumbnail-avatar', 100, 100, true );

4. Added these lines to the bottom of functions.php

I just pasted the following lines to the bottom of my functions.php file. 

/**
 * Stop generating medium_large image
 */
function add_image_insert_override( $sizes ){
    unset( $sizes[ 'thumbnail' ]);
    unset( $sizes[ 'medium' ]);
    unset( $sizes[ 'medium_large' ] );
    unset( $sizes[ 'large' ]);
    unset( $sizes[ 'full' ] );
    return $sizes;
}
add_filter( 'intermediate_image_sizes_advanced', 'add_image_insert_override' );
 

Thanks to Grim who posted this on a StackOverflow thread.

Conclusion

Finally, I was able to make it so that Wordpress doesn't create all of those extra images. I don't need those images because I'm just using Wordpress to aggregate posts on a non-public web site. So try this at your own risk. But it completely worked.

Share

Comments (0)

No comments found!

Write new comment