• Hi there!

    I’m trying to use the ‘crop_thumbnails_filename’ hook to change the name of an image file when it’s cropped. However, when I use the following code the URL being output on the frontend changes but it no longer displays the image.

    function changeCroppedFileName($file) {
    	$filePathInfo = pathinfo($file);
    
    	$filename = $filePathInfo['filename'];
    	$extension = $filePathInfo['extension'];
    
    	$date = new DateTime();
    	$timestamp = $date->getTimestamp();
    
    	$newPath = $filename.'-'.$timestamp.'.'.$extension;
    
    	return $newPath;
    }
    add_filter( 'crop_thumbnails_filename', 'changeCroppedFileName' );

    Is there something else I need to do to save the image with the new URL?

  • The topic ‘‘crop_thumbnails_filename’ hook doesn’t save image’ is closed to new replies.