W3cubDocs

/WordPress

remove_block_asset_path_prefix( string $asset_handle_or_path ): string

Removes the block asset’s path prefix if provided.

Parameters

$asset_handle_or_pathstringrequired
Asset handle or prefixed path.

Return

string Path without the prefix or the original value.

Source

function remove_block_asset_path_prefix( $asset_handle_or_path ) {
	$path_prefix = 'file:';
	if ( ! str_starts_with( $asset_handle_or_path, $path_prefix ) ) {
		return $asset_handle_or_path;
	}
	$path = substr(
		$asset_handle_or_path,
		strlen( $path_prefix )
	);
	if ( str_starts_with( $path, './' ) ) {
		$path = substr( $path, 2 );
	}
	return $path;
}

Changelog

Version Description
5.5.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/remove_block_asset_path_prefix