trailingslashit() WordPress Function

The trailingslashit() function is used to add a trailing slash to a string. This is useful for ensuring that a string ends with a slash for use in a URL.

trailingslashit( string $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.


Top ↑

Parameters

$string

(string)(Required)What to add the trailing slash to.


Top ↑

Return

(string) String with trailing slash added.


Top ↑

Source

File: wp-includes/formatting.php

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


Top ↑

Changelog

Changelog
VersionDescription
1.2.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More