W3cubDocs

/WordPress

trailingslashit( string $value ): string

Appends a trailing slash.

Description

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.

Parameters

$valuestringrequired
Value to which trailing slash will be added.

Return

string String with trailing slash added.

Source

function trailingslashit( $value ) {
	return untrailingslashit( $value ) . '/';
}

Changelog

Version Description
1.2.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/trailingslashit