function _wp_relative_upload_path( $path ) {}

Return relative path to an uploaded file.
The path is relative to the current upload dir.


  • string $path: Full path to the file

Return values

returns:relative path on success, unchanged path on failure.

Defined filters

  • _wp_relative_upload_path
    apply_filters( '_wp_relative_upload_path', $new_path, $path )

Source code

function _wp_relative_upload_path( $path ) {

	$new_path = $path;

	if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) {

		if ( 0 === strpos($new_path, $uploads['basedir']) ) {

				$new_path = str_replace($uploads['basedir'], '', $new_path);

				$new_path = ltrim($new_path, '/');



	return apply_filters( '_wp_relative_upload_path', $new_path, $path );



No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: