Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi there,

    Unfortunately, that is the case and according to this link it is considered as wont fix:

    https://core.trac.wordpress.org/ticket/32378

    You are welcome to ask again there to see if there is a chance to re-consider that.

    Best regards,

    Christopher Amirian

    Thread Starter patbell101

    (@patbell101)

    I found this snippet which copies filename to title when uploading, except its the full path – I need to strip the filename without path and extension. ANy help please?

    /**
     * Override the meta title for jpeg/tiff images
     * 
     * @link http://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 ) )    
            $meta['title'] = ''; // <-- Edit this to your needs!
    
        return $meta;
    
    }, 10, 3 );

    Hi there,

    Maybe this change can help?

    /**
     * Override the meta title for jpeg/tiff images
     * 
     * @link http://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.

    Thread Starter patbell101

    (@patbell101)

    Perfect.

    Thanks

    My pleasure 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Uploading Olympus images lose titles’ is closed to new replies.