trailingslashit( string $string )

Appends a trailing slash.


Description 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 Parameters

$string

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


Top ↑

Return Return

(string) String with trailing slash added.


Top ↑

Source Source

File: wp-includes/formatting.php

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

Top ↑

Changelog Changelog

Changelog
Version Description
1.2.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 2 content
    Contributed by Brad Davis

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

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

    To include a php file using the require statement

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

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