WordPress.org

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp normalize path

Description

Call the functions to normalize a filesystem path. This function is mainly for windows based server, to replaces backslashes with forward slashes, and ensures no duplicate slashes exist.

Usage

<?php wp_normalize_path($path); ?>

Parameters

$path
(string) (required) Path to normalize.
Default: None

Return Values

(string) 
Normalized path.

Examples

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
     * 
     */

     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');   

print_r($bS_incl_path); shows

Using this function:

C:/xampp/htdocs/boot_strap/wp-content/themes/boot_Strap/inc

Without this function:

C:\xampp\htdocs\boot_strap/wp-content/themes/boot_Strap/inc

On a Windows server.


Change Log

Since: 3.9

Source File

wp_normalize_path() is located in wp-includes/functions.php.