Function: user_trailingslashit

user_trailingslashit( string $string, string $type_of_url )

Retrieves a trailing-slashed string if the site is set for adding trailing slashes.

Conditionally adds a trailing slash if the permalink structure has a trailing slash, strips the trailing slash if not. The string is passed through the \'user_trailingslashit' filter. Will remove trailing slash from string, if site is not set to have them.

Parameters

Name Type(s) Default Value Description
$string string

URL with or without a trailing slash.

$type_of_url string ''

Optional. The type of URL being considered (e.g. single, category, etc) for use in the filter. Default empty string.

Returns

string

The URL with the trailing slash appended or stripped.

WordPress Developer Newsletter

Stay on top of the latest WordPress API changes, developer tool updates, security alerts and more.