Hi there,
Maybe this change can help?
/**
* Override the meta title for jpeg/tiff images
*
* @link https://wordpress.stackexchange.com/a/192779/26350
*/
add_filter( 'wp_read_image_metadata', function( $meta, $file, $sourceImageType )
{
$image_types = [ IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM ];
if( ! empty( $meta['title'] ) && in_array( $sourceImageType, $image_types ) ) {
// get filename without path
$filename = basename($file);
// strip extension from filename
$filename_no_ext = pathinfo($filename, PATHINFO_FILENAME);
// set title to filename without extension
$meta['title'] = $filename_no_ext;
}
return $meta;
}, 10, 3 );
The code uses the basename()
function to get the filename, and the pathinfo()
function to strip out the extension.
This code will modify the title to be the filename without extension for JPEG and TIFF images. Please ensure you backup your site before making any changes, and test this in a safe environment before implementing on a live site.