remove_block_asset_path_prefix() WordPress Function

This function will remove the block asset path prefix from the given string. This is useful when you need to enqueue a script or stylesheet that is located in the blocks directory.

remove_block_asset_path_prefix( string $asset_handle_or_path ) #

Removes the block asset’s path prefix if provided.


Parameters

$asset_handle_or_path

(string)(Required)Asset handle or prefixed path.


Top ↑

Return

(string) Path without the prefix or the original value.


Top ↑

Source

File: wp-includes/blocks.php

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


Top ↑

Changelog

Changelog
VersionDescription
5.5.0Introduced.

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.