Change the filename format of saved featured images

Does anyone know how I could change the way wordpress saves the featured image’s additional image sizes?

Right now I have the main image saving like so:

Read More
test_builder_banner_2.jpg

and for each additional image size it saves like so:

test_builder_banner-610x260.jpg

All I want to do is get rid of the “-” between the name of the file and the file size, and replace it with an underscore.

Is there a filter I can use or something of that sort?

Related posts

1 comment

  1. There is a filter to use for the array containing the filename that is saved to postmeta but since there are no filters available to change the filename before it is saved you have to manually change it using rename().

    function wpse_filter_image_resize_name( $filename ) {
        $new_name = preg_replace( "/-(?<match>\d)/ui", "_$1", $filename );
    
        if ( rename( $filename, $new_name ) )
            return $new_name;
    
        return $filename;
    }
    add_filter( 'image_make_intermediate_size', 'wpse_filter_image_resize_name' );
    

Comments are closed.