wp_normalize_path( string $path )

Normalize a filesystem path.

Description 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 Parameters


(string) (Required) Path to normalize.

Top ↑

Return Return

(string) Normalized path.

Top ↑

Source Source

File: wp-includes/functions.php

function wp_normalize_path( $path ) {
	$path = str_replace( '\\', '/', $path );
	$path = preg_replace( '|(?<=.)/+|', '/', $path );
	if ( ':' === substr( $path, 1, 1 ) ) {
		$path = ucfirst( $path );
	return $path;

Top ↑

Changelog Changelog

Version Description
4.5.0 Allows for Windows network shares.
4.4.0 Ensures upper-case drive letters on Windows systems.
3.9.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note content
    Contributed by Codex


    A Simple example to normalize the theme include path

        $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
            $bS_incl_path = wp_normalize_path($bS_incl_path);
        define('THM_INC', $bS_incl_path);
        require_once (THM_INC. '/wp_bootstrap_navwalker.php');   

    print_r($bS_incl_path); shows

    Using this function:


    Without this function:


    On a Windows server.

You must log in before being able to contribute a note or feedback.