Change the filename format of saved featured images

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' );

Leave a Comment