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

_wp_get_attachment_relative_path() WordPress Function

This function retrieves the relative path for an attachment. It is useful for getting the path of an attachment relative to the current file. This function can be used with any type of attachment.

_wp_get_attachment_relative_path( string $file ) #

Get the attachment path relative to the upload directory.


Parameters

$file

(string)(Required)Attachment file name.


Top ↑

Return

(string) Attachment path relative to the upload directory.


Top ↑

Source

File: wp-includes/media.php

function _wp_get_attachment_relative_path( $file ) {
	$dirname = dirname( $file );

	if ( '.' === $dirname ) {
		return '';
	}

	if ( false !== strpos( $dirname, 'wp-content/uploads' ) ) {
		// Get the directory name relative to the upload directory (back compat for pre-2.7 uploads).
		$dirname = substr( $dirname, strpos( $dirname, 'wp-content/uploads' ) + 18 );
		$dirname = ltrim( $dirname, '/' );
	}

	return $dirname;
}


Top ↑

Changelog

Changelog
VersionDescription
4.4.1Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More