untrailingslashit() WordPress Function

The untrailingslashit() function is a utility function that strips the trailing slash from a string, if it exists. This is useful for sanitizing paths and URLs before inserting them into the database, or for displaying purposes. It is also useful for preventing double slash problems when using WordPress permalinks.

untrailingslashit( string $string ) #

Removes trailing forward slashes and backslashes if they exist.


Description

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 remove the trailing slashes from.


Top ↑

Return

(string) String without the trailing slashes.


Top ↑

Source

File: wp-includes/formatting.php

function untrailingslashit( $string ) {
	return rtrim( $string, '/\\' );
}


Top ↑

Changelog

Changelog
VersionDescription
2.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