WordPress at a glance

user_trailingslashit() WP 1.0

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.

  • Global. WP_Rewrite. $wp_rewrite
Is the basis for: get_comments_pagenum_link()
✈ 1 time = 0.00005s = very fast | 50000 times = 0.076s = speed of light
Hooks in function

String. The URL with the trailing slash appended or stripped.


user_trailingslashit( $string, $type_of_url );
$string(string) (required)
URL with or without a trailing slash.
The type of URL being considered (e.g. single, category, etc) for use in the filter.
Default: empty string

Code of user trailingslashit: wp-includes/link-template.php VER 5.1.1

function user_trailingslashit( $string, $type_of_url = '' ) {
	global $wp_rewrite;
	if ( $wp_rewrite->use_trailing_slashes ) {
		$string = trailingslashit( $string );
	} else {
		$string = untrailingslashit( $string );

	 * Filters the trailing-slashed string, depending on whether the site is set to use trailing slashes.
	 * @since 2.2.0
	 * @param string $string      URL with or without a trailing slash.
	 * @param string $type_of_url The type of URL being considered. Accepts 'single', 'single_trackback',
	 *                            'single_feed', 'single_paged', 'commentpaged', 'paged', 'home', 'feed',
	 *                            'category', 'page', 'year', 'month', 'day', 'post_type_archive'.
	return apply_filters( 'user_trailingslashit', $string, $type_of_url );

Related Functions

From category: Formatting

No comments
    Hello, !     Log In . Register