Title: get_block_asset_url
Published: November 8, 2023
Last modified: April 28, 2025

---

# get_block_asset_url( string $path ): string|false

## In this article

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

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

Gets the URL to a block asset.

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

 `$path`stringrequired

A normalized path to a block asset.

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

 string|false The URL to the block asset or false on failure.

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

    ```php
    function get_block_asset_url( $path ) {
    	if ( empty( $path ) ) {
    		return false;
    	}

    	// Path needs to be normalized to work in Windows env.
    	static $wpinc_path_norm = '';
    	if ( ! $wpinc_path_norm ) {
    		$wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) );
    	}

    	if ( str_starts_with( $path, $wpinc_path_norm ) ) {
    		return includes_url( str_replace( $wpinc_path_norm, '', $path ) );
    	}

    	static $template_paths_norm = array();

    	$template = get_template();
    	if ( ! isset( $template_paths_norm[ $template ] ) ) {
    		$template_paths_norm[ $template ] = wp_normalize_path( realpath( get_template_directory() ) );
    	}

    	if ( str_starts_with( $path, trailingslashit( $template_paths_norm[ $template ] ) ) ) {
    		return get_theme_file_uri( str_replace( $template_paths_norm[ $template ], '', $path ) );
    	}

    	if ( is_child_theme() ) {
    		$stylesheet = get_stylesheet();
    		if ( ! isset( $template_paths_norm[ $stylesheet ] ) ) {
    			$template_paths_norm[ $stylesheet ] = wp_normalize_path( realpath( get_stylesheet_directory() ) );
    		}

    		if ( str_starts_with( $path, trailingslashit( $template_paths_norm[ $stylesheet ] ) ) ) {
    			return get_theme_file_uri( str_replace( $template_paths_norm[ $stylesheet ], '', $path ) );
    		}
    	}

    	return plugins_url( basename( $path ), $path );
    }
    ```

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

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

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

Retrieves the URL of a file in the theme.

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

Retrieves name of the active theme.

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

Retrieves template directory path for the active theme.

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

Retrieves stylesheet directory path for the active theme.

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

Whether a child theme is in use.

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

Retrieves name of the current stylesheet.

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

Normalizes a filesystem path.

  | 
| [includes_url()](https://developer.wordpress.org/reference/functions/includes_url/)`wp-includes/link-template.php` |

Retrieves the URL to the includes directory.

  | 
| [plugins_url()](https://developer.wordpress.org/reference/functions/plugins_url/)`wp-includes/link-template.php` |

Retrieves a URL within the plugins or mu-plugins directory.

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

Appends a trailing slash.

  |

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

| Used by | Description | 
| [register_block_script_module_id()](https://developer.wordpress.org/reference/functions/register_block_script_module_id/)`wp-includes/blocks.php` |

Finds a script module ID for the selected block metadata field. It detects when a path to file was provided and optionally finds a corresponding asset file with details necessary to register the script module under with an automatically generated module ID. It returns unprocessed script module ID otherwise.

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

Finds a script handle for the selected block metadata field. It detects when a path to file was provided and optionally finds a corresponding asset file with details necessary to register the script under automatically generated handle name. It returns unprocessed script handle otherwise.

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

Finds a style handle for the block metadata field. It detects when a path to file was provided and registers the style under automatically generated handle name. It returns unprocessed style handle otherwise.

  |

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

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

## User Contributed Notes

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