wp_get_original_image_path()
Gets the path of the original image (not its resized copy) by the specified attachment ID.
This function is similar to get_attached_file(), however, some images may be processed after upload. For example, when uploading very large photos, see below for more details. In this case, the attached "full" size file is usually replaced with a processed version of the original image. This function returns the path to the originally uploaded file.
Use wp_get_original_image_url() when you need to get the URL, not the path of the original image.
Using this function makes sense only when a very large image has been uploaded - more than 2560px in width or height.
If the image was uploaded in WordPress 5.2 or lower, or the image has dimensions in height and width less than specified in the filter big_image_size_threshold (default 2560), then this function will work exactly the same as the get_attached_file() function, that is, when cropping the image, it will return the path to the cropped version, not the original.
This happens when the image dimensions are less than specified in the filter big_image_size_threshold (default 2560). In this case, when uploading the image, the function _wp_image_meta_replace_original() will not be triggered, which adds the original_image
parameter to the metadata (this parameter stores the original path to the image), this parameter is used by the described function wp_get_original_image_path()
.
For more details, read in a separate note.
The function checks that the specified attachment is indeed an image, otherwise it returns false. Such a check makes the code more stable.
Hooks from the function
Returns
String|false
. Path to the original image file or false if the attachment is not an image or the specified attachment does not exist.
Usage
wp_get_original_image_path( $attachment_id );
- $attachment_id(integer) (required)
- ID of the attachment (image).
Examples
#1 Display the path to the picture
$attach_path = wp_get_original_image_path( 516 ); if ( $attach_path ) { echo $attach_path; } else { echo 'This file is not an image or the specified image does not exist'; }
Changelog
Since 5.3.0 | Introduced. |
Since 5.4.0 | Added the $unfiltered parameter. |