trailingslashit

Appends a trailing slash.

Description

(string) trailingslashit( (string) $string ); 

Will remove trailing forward and backslashes if it exists already before adding a trailing forward slash. This prevents double slashing a string or path.

The primary use of this is for paths and thus should be used for paths. It is not restricted to paths and offers no specific path support.

Returns (string)

String with trailing slash added.

Parameters (1)

0. $string (string)
What to add the trailing slash to.

Usage

  1. if ( !function_exists( 'trailingslashit' ) ) { 
  2. require_once ABSPATH . WPINC . '/formatting.php'; 
  3.  
  4. // What to add the trailing slash to. 
  5. $string = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = trailingslashit($string); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/formatting.php  
  1. function trailingslashit( $string ) { 
  2. return untrailingslashit( $string ) . '/';