Title: wp_normalize_path
Published: April 25, 2014
Last modified: February 24, 2026

---

# wp_normalize_path( string $path ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_normalize_path/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/wp_normalize_path/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_normalize_path/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_normalize_path/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_normalize_path/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_normalize_path/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_normalize_path/?output_format=md#user-contributed-notes)

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

Normalizes a filesystem path.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_normalize_path/?output_format=md#description)󠁿

On windows systems, replaces backslashes with forward slashes and forces upper-case
drive letters.
Allows for two leading slashes for Windows network shares, but ensures
that all other duplicate slashes are reduced to a single.

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

 `$path`stringrequired

Path to normalize.

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

 string Normalized path.

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

    ```php
    function wp_normalize_path( $path ) {
    	$wrapper = '';

    	if ( wp_is_stream( $path ) ) {
    		list( $wrapper, $path ) = explode( '://', $path, 2 );

    		$wrapper .= '://';
    	}

    	// Standardize all paths to use '/'.
    	$path = str_replace( '\\', '/', $path );

    	// Replace multiple slashes down to a singular, allowing for network shares having two slashes.
    	$path = preg_replace( '|(?<=.)/+|', '/', $path );

    	// Windows paths should uppercase the drive letter.
    	if ( ':' === substr( $path, 1, 1 ) ) {
    		$path = ucfirst( $path );
    	}

    	return $wrapper . $path;
    }
    ```

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

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

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

Tests if a given path is a stream URL

  |

| Used by | Description | 
| [WP_Block_Metadata_Registry::get_collection_block_metadata_files()](https://developer.wordpress.org/reference/classes/wp_block_metadata_registry/get_collection_block_metadata_files/)`wp-includes/class-wp-block-metadata-registry.php` |

Gets the list of absolute paths to all block metadata files that are part of the given collection.

  | 
| [WP_Block_Metadata_Registry::get_default_collection_roots()](https://developer.wordpress.org/reference/classes/wp_block_metadata_registry/get_default_collection_roots/)`wp-includes/class-wp-block-metadata-registry.php` |

Gets the default collection root directory paths.

  | 
| [WP_Block_Metadata_Registry::get_metadata()](https://developer.wordpress.org/reference/classes/wp_block_metadata_registry/get_metadata/)`wp-includes/class-wp-block-metadata-registry.php` |

Retrieves block metadata for a given block within a specific collection.

  | 
| [WP_Block_Metadata_Registry::register_collection()](https://developer.wordpress.org/reference/classes/wp_block_metadata_registry/register_collection/)`wp-includes/class-wp-block-metadata-registry.php` |

Registers a block metadata collection.

  | 
| [WP_Font_Collection::load_from_json()](https://developer.wordpress.org/reference/classes/wp_font_collection/load_from_json/)`wp-includes/fonts/class-wp-font-collection.php` |

Loads font collection data from a JSON file or URL.

  | 
| [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.

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

Gets the URL to a block asset.

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

Reads and decodes a JSON file.

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

Creates an export of the current templates and template parts from the site editor at the specified path in a ZIP file.

  | 
| [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.

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

Registers a block type from the metadata stored in the `block.json` file.

  | 
| [Theme_Installer_Skin::do_overwrite()](https://developer.wordpress.org/reference/classes/theme_installer_skin/do_overwrite/)`wp-admin/includes/class-theme-installer-skin.php` |

Checks if the theme can be overwritten and outputs the HTML for overwriting a theme on upload.

  | 
| [WP_Recovery_Mode::get_extension_for_error()](https://developer.wordpress.org/reference/classes/wp_recovery_mode/get_extension_for_error/)`wp-includes/class-wp-recovery-mode.php` |

Gets the extension that the error occurred in.

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

Internal helper function to find the plugin from a meta box callback.

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

Deletes a file if its path is within the given directory.

  | 
| [wp_privacy_generate_personal_data_export_file()](https://developer.wordpress.org/reference/functions/wp_privacy_generate_personal_data_export_file/)`wp-admin/includes/privacy-tools.php` |

Generate the personal data export file.

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

Validates a URL for use in a redirect.

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

Returns a comma-separated string or array of functions that have been called to get to the current point in code.

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

Validates a file name and path against an allowed set of rules.

  | 
| [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.

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

Gets the basename of a plugin.

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

Register a plugin’s real path.

  |

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

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

| Version | Description | 
| [4.9.7](https://developer.wordpress.org/reference/since/4.9.7/) | Allows for PHP file wrappers. | 
| [4.5.0](https://developer.wordpress.org/reference/since/4.5.0/) | Allows for Windows network shares. | 
| [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Ensures upper-case drive letters on Windows systems. | 
| [3.9.0](https://developer.wordpress.org/reference/since/3.9.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_normalize_path/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 2 content](https://developer.wordpress.org/reference/functions/wp_normalize_path/?output_format=md#comment-content-1544)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/wp_normalize_path/#comment-1544)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_normalize_path%2F%23comment-1544)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_normalize_path%2F%23comment-1544)
 4.  **Example**
 5.  A Simple example to normalize the theme include path
 6.      ```php
             $bS_incl_path = get_template_directory() . '/inc';
     
             /**
              * Define theme include path
              * 
              * Normalize the include path to be safe on windows hosts
              * @return string Normalized path
              * require min WordPress version 3.9
              * @since boot_Strap 1.0.1
              * 
              */
     
              if(function_exists('wp_normalize_path')){
     
                 $bS_incl_path = wp_normalize_path($bS_incl_path);
              }
     
             define('THM_INC', $bS_incl_path);
     
             require_once (THM_INC. '/wp_bootstrap_navwalker.php');   
         ```
     
 7.  `print_r($bS_incl_path);` shows
 8.  Using this function:
 9.      ```php
         C:/xampp/htdocs/boot_strap/wp-content/themes/boot_Strap/inc
         ```
     
 10. Without this function:
 11.     ```php
         C:\xampp\htdocs\boot_strap/wp-content/themes/boot_Strap/inc
         ```
     
 12. On a Windows server.
 13.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_normalize_path%2F%3Freplytocom%3D1544%23feedback-editor-1544)

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