trailingslashit()
Adds a slash / at the end of the string.
Before adding /, the function removes all / at the end of the string. This prevents double slashes in file paths or links.
Uses: untrailingslashit()
Used By: user_trailingslashit()
No Hooks.
Returns
String. A string with / added at the end.
Usage
$string = trailingslashit( $string );
- $string(string) (required)
- The string to which you need to add / at the end.
Examples
#1 Demo:
echo trailingslashit( "any (string)//" ); //> any (string)/ echo trailingslashit( "any (string)" ) ); //> any (string)/ echo trailingslashit( trailingslashit( 'some/dir/' ) ); //> some/dir/
#2 Examples that you could use the this function for:
To enqueue a style.css file:
wp_enqueue_style( 'main-css', trailingslashit( get_template_directory_uri() ) . 'style.css' );
To include a php file using the require statement:
require trailingslashit( get_template_directory() ) . 'inc/custom-theme-functions.php';
Changelog
| Since 1.2.0 | Introduced. |
trailingslashit() trailingslashit code WP 6.9.1
function trailingslashit( $value ) {
return untrailingslashit( $value ) . '/';
}