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

VersionDescription
1.2.0Introduced.

User Contributed Notes

  1. Skip to note 4 content

    Two examples that you could use the trailingslashit() function for:
    To enqueue a style.css file

    wp_enqueue_style( 'main-css', trailingslashit( get_template_directory_uri() ) . 'style.css' );

    To include a php file using the require statement

    require trailingslashit( get_template_directory() ) . 'inc/custom-theme-functions.php';

You must log in before being able to contribute a note or feedback.