Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

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?

share|improve this question

1 Answer 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' );
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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