Title: wp_get_original_image_path
Published: November 12, 2019
Last modified: May 20, 2026

---

# wp_get_original_image_path( int $attachment_id, bool $unfiltered = false ): string|false

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_get_original_image_path/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/wp_get_original_image_path/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_get_original_image_path/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_get_original_image_path/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/wp_get_original_image_path/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/wp_get_original_image_path/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_get_original_image_path/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_get_original_image_path/?output_format=md#wp--skip-link--target)

Retrieves the path to an uploaded image file.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_get_original_image_path/?output_format=md#description)󠁿

Similar to `get_attached_file()` however some images may have been processed after
uploading to make them suitable for web use. In this case the attached “full” size
file is usually replaced with a scaled down version of the original image. This 
function always returns the path to the originally uploaded image file.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_get_original_image_path/?output_format=md#parameters)󠁿

 `$attachment_id`intrequired

Attachment ID.

`$unfiltered`booloptional

Passed through to `get_attached_file()`.

Default:`false`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_get_original_image_path/?output_format=md#return)󠁿

 string|false Path to the original image file or false if the attachment is not 
an image.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_get_original_image_path/?output_format=md#source)󠁿

    ```php
    function wp_get_original_image_path( $attachment_id, $unfiltered = false ) {
    	if ( ! wp_attachment_is_image( $attachment_id ) ) {
    		return false;
    	}

    	$image_meta = wp_get_attachment_metadata( $attachment_id );
    	$image_file = get_attached_file( $attachment_id, $unfiltered );

    	if ( empty( $image_meta['original_image'] ) ) {
    		$original_image = $image_file;
    	} else {
    		$original_image = path_join( dirname( $image_file ), $image_meta['original_image'] );
    	}

    	/**
    	 * Filters the path to the original image.
    	 *
    	 * @since 5.3.0
    	 *
    	 * @param string $original_image Path to original image file.
    	 * @param int    $attachment_id  Attachment ID.
    	 */
    	return apply_filters( 'wp_get_original_image_path', $original_image, $attachment_id );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/post.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/post.php#L8460)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/post.php#L8460-L8483)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/wp_get_original_image_path/?output_format=md#hooks)󠁿

 [apply_filters( ‘wp_get_original_image_path’, string $original_image, int $attachment_id )](https://developer.wordpress.org/reference/hooks/wp_get_original_image_path/)

Filters the path to the original image.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_get_original_image_path/?output_format=md#related)󠁿

| Uses | Description | 
| [path_join()](https://developer.wordpress.org/reference/functions/path_join/)`wp-includes/functions.php` |

Joins two filesystem paths together.

  | 
| [wp_attachment_is_image()](https://developer.wordpress.org/reference/functions/wp_attachment_is_image/)`wp-includes/post.php` |

Determines whether an attachment is an image.

  | 
| [wp_get_attachment_metadata()](https://developer.wordpress.org/reference/functions/wp_get_attachment_metadata/)`wp-includes/post.php` |

Retrieves attachment metadata for attachment ID.

  | 
| [get_attached_file()](https://developer.wordpress.org/reference/functions/get_attached_file/)`wp-includes/post.php` |

Retrieves attached file path based on attachment ID.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/wp_get_original_image_path/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_get_original_image_path/?output_format=md#)

| Used by | Description | 
| [WP_REST_Attachments_Controller::get_attachment_filename()](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/get_attachment_filename/)`wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php` |

Gets the attachment’s original file name.

  | 
| [WP_REST_Attachments_Controller::get_attachment_filesize()](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/get_attachment_filesize/)`wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php` |

Gets the attachment’s file size in bytes.

  | 
| [WP_REST_Attachments_Controller::edit_media_item()](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/edit_media_item/)`wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php` |

Applies edits to a media item and creates a new attachment record.

  | 
| [wp_get_missing_image_subsizes()](https://developer.wordpress.org/reference/functions/wp_get_missing_image_subsizes/)`wp-admin/includes/image.php` |

Compare the existing image sub-sizes (as saved in the attachment meta) to the currently registered image sub-sizes, and return the difference.

  | 
| [wp_update_image_subsizes()](https://developer.wordpress.org/reference/functions/wp_update_image_subsizes/)`wp-admin/includes/image.php` |

If any of the currently registered image sub-sizes are missing, create them and update the image meta data.

  | 
| [attachment_submitbox_metadata()](https://developer.wordpress.org/reference/functions/attachment_submitbox_metadata/)`wp-admin/includes/media.php` |

Displays non-editable attachment metadata in the publish meta box.

  | 
| [wp_prepare_attachment_for_js()](https://developer.wordpress.org/reference/functions/wp_prepare_attachment_for_js/)`wp-includes/media.php` |

Prepares an attachment post object for JS, where it is expected to be JSON-encoded and fit into an Attachment model.

  |

[Show 2 more](https://developer.wordpress.org/reference/functions/wp_get_original_image_path/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_get_original_image_path/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_get_original_image_path/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.4.0](https://developer.wordpress.org/reference/since/5.4.0/) | Added the `$unfiltered` parameter. | 
| [5.3.0](https://developer.wordpress.org/reference/since/5.3.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_original_image_path%2F)
before being able to contribute a note or feedback.