Title: _wp_relative_upload_path
Published: April 25, 2014
Last modified: February 24, 2026

---

# _wp_relative_upload_path( string $path ): string

## In this article

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

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

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Returns relative path to an uploaded file.

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

The path is relative to the current upload dir.

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

 `$path`stringrequired

Full path to the file.

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

 string Relative path on success, unchanged path on failure.

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

    ```php
    function _wp_relative_upload_path( $path ) {
    	$new_path = $path;

    	$uploads = wp_get_upload_dir();
    	if ( str_starts_with( $new_path, $uploads['basedir'] ) ) {
    			$new_path = str_replace( $uploads['basedir'], '', $new_path );
    			$new_path = ltrim( $new_path, '/' );
    	}

    	/**
    	 * Filters the relative path to an uploaded file.
    	 *
    	 * @since 2.9.0
    	 *
    	 * @param string $new_path Relative path to the file.
    	 * @param string $path     Full path to the file.
    	 */
    	return apply_filters( '_wp_relative_upload_path', $new_path, $path );
    }
    ```

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

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

 [apply_filters( ‘_wp_relative_upload_path’, string $new_path, string $path )](https://developer.wordpress.org/reference/hooks/_wp_relative_upload_path/)

Filters the relative path to an uploaded file.

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

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

Retrieves uploads directory information.

  | 
| [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.

  |

| Used by | Description | 
| [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_image_meta_replace_original()](https://developer.wordpress.org/reference/functions/_wp_image_meta_replace_original/)`wp-admin/includes/image.php` |

Updates the attached file and image meta data when the original image was edited.

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

Creates image sub-sizes, adds the new data to the image meta `sizes` array, and updates the image metadata.

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

Restores the metadata for a given attachment.

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

Saves image to post, along with enqueued changes in `$_REQUEST['history']`.

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

Updates attachment file path based on attachment ID.

  |

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

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

| Version | Description | 
| [2.9.0](https://developer.wordpress.org/reference/since/2.9.0/) | Introduced. |

## User Contributed Notes

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