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.
Return #Return
(string) String with trailing slash added.
Source #Source
File: wp-includes/formatting.php
function trailingslashit( $string ) { return untrailingslashit( $string ) . '/'; }
Expand full source code Collapse full source code View on Trac
Changelog #Changelog
Version | Description |
---|---|
1.2.0 | Introduced. |
Related #Related
Uses #Uses
Uses | Description |
---|---|
wp-includes/formatting.php: untrailingslashit() |
Removes trailing forward slashes and backslashes if they exist. |
Used By #Used By
Used By | Description |
---|---|
wp-includes/ms-site.php: wp_normalize_site_data() |
Normalizes data for a site prior to inserting or updating in the database. |
wp-includes/l10n.php: load_script_textdomain() |
Loads the script translated strings. |
wp-includes/functions.php: wp_privacy_exports_dir() |
Returns the directory used to store personal data export files. |
wp-includes/functions.php: wp_privacy_exports_url() |
Returns the URL of the directory used to store personal data export files. |
wp-includes/functions.php: wp_delete_file_from_directory() |
Deletes a file if its path is within the given directory. |
wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php: WP_REST_Terms_Controller::prepare_links() |
Prepares links for the request. |
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::prepare_links() |
Prepares links for the request. |
wp-includes/link-template.php: wp_get_canonical_url() |
Returns the canonical URL for a post. |
wp-includes/functions.php: _wp_upload_dir() |
A non-filtered, non-cached version of wp_upload_dir() that doesn’t check the path. |
wp-includes/rest-api.php: get_rest_url() |
Retrieves the URL to a REST endpoint on a site. |
wp-includes/embed.php: get_post_embed_url() |
Retrieves the URL to embed a specific post in an iframe. |
wp-includes/media.php: wp_calculate_image_srcset() |
A helper function to calculate the image sources to include in a ‘srcset’ attribute. |
wp-admin/includes/update-core.php: _upgrade_422_remove_genericons() |
Cleans up Genericons example files. |
wp-admin/includes/network.php: network_step2() |
Prints step 2 for Network installation process. |
wp-admin/includes/class-theme-upgrader.php: Theme_Upgrader::delete_old_theme() |
Delete the old theme during an upgrade. |
wp-admin/includes/class-core-upgrader.php: Core_Upgrader::upgrade() |
Upgrade WordPress core. |
wp-admin/includes/class-theme-upgrader.php: Theme_Upgrader::check_package() |
Check that the package source contains a valid theme. |
wp-admin/includes/class-plugin-upgrader.php: Plugin_Upgrader::check_package() |
Check a source package to be sure it contains a plugin. |
wp-admin/includes/class-plugin-upgrader.php: Plugin_Upgrader::delete_old_plugin() |
Delete the old plugin during an upgrade. |
wp-admin/includes/class-wp-upgrader.php: WP_Upgrader::install_package() |
Install a package. |
wp-admin/includes/class-wp-filesystem-ssh2.php: WP_Filesystem_SSH2::cwd() |
Gets the current working directory. |
wp-admin/includes/theme.php: delete_theme() |
Remove a theme |
wp-admin/includes/class-wp-filesystem-ftpext.php: WP_Filesystem_FTPext::is_dir() |
Checks if resource is a directory. |
wp-admin/includes/class-wp-filesystem-ftpext.php: WP_Filesystem_FTPext::cwd() |
Gets the current working directory. |
wp-admin/includes/class-wp-filesystem-ftpext.php: WP_Filesystem_FTPext::delete() |
Deletes a file or directory. |
wp-admin/includes/class-wp-filesystem-base.php: WP_Filesystem_Base::find_folder() |
Locates a folder on the remote filesystem. |
wp-admin/includes/class-wp-filesystem-base.php: WP_Filesystem_Base::search_for_folder() |
Locates a folder on the remote filesystem. |
wp-admin/includes/class-wp-filesystem-direct.php: WP_Filesystem_Direct::delete() |
Deletes a file or directory. |
wp-admin/includes/class-wp-filesystem-direct.php: WP_Filesystem_Direct::chgrp() |
Changes the file group. |
wp-admin/includes/class-wp-filesystem-direct.php: WP_Filesystem_Direct::chmod() |
Changes filesystem permissions. |
wp-admin/includes/plugin.php: delete_plugins() |
Remove directory and files of a plugin for a list of plugins. |
wp-admin/includes/update-core.php: update_core() |
Upgrades the core of WordPress. |
wp-admin/includes/class-wp-filesystem-ftpsockets.php: WP_Filesystem_ftpsockets::cwd() |
Gets the current working directory. |
wp-admin/includes/file.php: get_filesystem_method() |
Determines which method to use for reading, writing, modifying, or deleting files on the filesystem. |
wp-admin/includes/file.php: get_home_path() |
Get the absolute filesystem path to the root of the WordPress installation |
wp-admin/includes/file.php: list_files() |
Returns a listing of all files in the specified folder and all subdirectories up to 100 levels deep. |
wp-admin/includes/file.php: unzip_file() |
Unzips a specified ZIP file to a location on the filesystem via the WordPress Filesystem Abstraction. |
wp-admin/includes/file.php: copy_dir() |
Copies a directory from one location to another via the WordPress Filesystem Abstraction. |
wp-includes/general-template.php: paginate_links() |
Retrieve paginated link for archive post pages. |
wp-includes/class-wp-theme.php: WP_Theme::scandir() |
Scans a directory for files of a certain extension. |
wp-includes/query.php: wp_old_slug_redirect() |
Redirect old slugs to the correct permalink. |
wp-includes/functions.php: get_temp_dir() |
Determine a writable directory for temporary files. |
wp-includes/link-template.php: get_comments_pagenum_link() |
Retrieves the comments page number link. |
wp-includes/link-template.php: paginate_comments_links() |
Displays or retrieves pagination links for the comments on the current post. |
wp-includes/link-template.php: get_pagenum_link() |
Retrieves the link for a page number. |
wp-includes/link-template.php: get_post_type_archive_feed_link() |
Retrieves the permalink for a post type archive feed. |
wp-includes/link-template.php: get_term_feed_link() |
Retrieves the feed link for a term. |
wp-includes/link-template.php: get_search_feed_link() |
Retrieves the permalink for the search results feed. |
wp-includes/link-template.php: get_post_comments_feed_link() |
Retrieves the permalink for the post comments feed. |
wp-includes/link-template.php: get_author_feed_link() |
Retrieves the feed link for a given author. |
wp-includes/link-template.php: get_attachment_link() |
Retrieves the permalink for an attachment. |
wp-includes/link-template.php: user_trailingslashit() |
Retrieves a trailing-slashed string if the site is set for adding trailing slashes. |
wp-includes/class-wp-admin-bar.php: WP_Admin_Bar::initialize() | |
wp-includes/class-wp-image-editor.php: WP_Image_Editor::get_output_format() |
Returns preferred mime-type and extension based on provided file’s extension and mime, or current file’s extension and mime. |
wp-includes/class-wp-image-editor.php: WP_Image_Editor::generate_filename() |
Builds an output filename based on current file, and adding proper suffix |
wp-includes/plugin.php: plugin_dir_path() |
Get the filesystem directory path (with trailing slash) for the plugin __FILE__ passed in. |
wp-includes/plugin.php: plugin_dir_url() |
Get the URL directory path (with trailing slash) for the plugin __FILE__ passed in. |
wp-includes/post-template.php: _wp_link_page() |
Helper function for wp_link_pages(). |
wp-includes/post.php: wp_get_attachment_url() |
Retrieve the URL for an attachment. |
wp-includes/class-wp-rewrite.php: WP_Rewrite::mod_rewrite_rules() |
Retrieves mod_rewrite-formatted rewrite rules to write to .htaccess. |
wp-includes/rewrite.php: url_to_postid() |
Examine a URL and try to determine the post ID it represents. |
wp-includes/canonical.php: redirect_guess_404_permalink() |
Attempts to guess the correct URL based on query vars |
wp-includes/canonical.php: redirect_canonical() |
Redirects incoming links to the proper URL based on the site url. |
wp-includes/ms-functions.php: domain_exists() |
Checks whether a site name is already taken. |
wp-includes/comment-template.php: get_trackback_url() |
Retrieve The current post’s trackback URL. |
wp-includes/comment-template.php: get_comment_link() |
Retrieve the link to a given comment. |
wp-includes/comment.php: weblog_ping() |
Send a pingback. |
wp-includes/class-wp-editor.php: _WP_Editors::editor_settings() |
User Contributed Notes #User Contributed Notes
You must log in before being able to contribute a note or feedback.
Basic Example
$path will now contain:
/home/julien/bin/dotfiles/
(Notice the trailing slash)
Two examples that you could use the trailingslashit() function for:
To enqueue a style.css file
To include a php file using the require statement