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
$value
stringrequired- Value to which trailing slash will be added.
Return
string String with trailing slash added.Source
function trailingslashit( $value ) {
return untrailingslashit( $value ) . '/';
}
Related
Uses | Description |
---|---|
untrailingslashit()wp-includes/formatting.php | Removes trailing forward slashes and backslashes if they exist. |
Used by | Description |
---|---|
get_block_asset_url()wp-includes/blocks.php | Gets the URL to a block asset. |
WP_Upgrader::move_to_temp_backup_dir()wp-admin/includes/class-wp-upgrader.php | Moves the plugin or theme being updated into a temporary backup directory. |
WP_Upgrader::restore_temp_backup()wp-admin/includes/class-wp-upgrader.php | Restores the plugin or theme from temporary backup. |
wp_opcache_invalidate_directory()wp-admin/includes/file.php | Attempts to clear the opcode cache for a directory of files. |
move_dir()wp-admin/includes/file.php | Moves a directory from one location to another. |
WP_REST_Global_Styles_Controller::prepare_links()wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php | Prepares links for the request. |
WP_REST_Menu_Locations_Controller::prepare_links()wp-includes/rest-api/endpoints/class-wp-rest-menu-locations-controller.php | Prepares links for the request. |
WP_REST_Server::match_request_to_handler()wp-includes/rest-api/class-wp-rest-server.php | Matches a request object to its handler. |
register_block_type_from_metadata()wp-includes/blocks.php | Registers a block type from the metadata stored in the |
WP_Site_Health::wp_cron_scheduled_check()wp-admin/includes/class-wp-site-health.php | Runs the scheduled event to check and update the latest site health status for the website. |
wp_normalize_site_data()wp-includes/ms-site.php | Normalizes data for a site prior to inserting or updating in the database. |
load_script_textdomain()wp-includes/l10n.php | Loads the script translated strings. |
wp_privacy_exports_dir()wp-includes/functions.php | Returns the directory used to store personal data export files. |
wp_privacy_exports_url()wp-includes/functions.php | Returns the URL of the directory used to store personal data export files. |
wp_delete_file_from_directory()wp-includes/functions.php | Deletes a file if its path is within the given directory. |
_load_textdomain_just_in_time()wp-includes/l10n.php | Loads plugin and theme text domains just-in-time. |
wp_get_canonical_url()wp-includes/link-template.php | Returns the canonical URL for a post. |
_wp_upload_dir()wp-includes/functions.php | A non-filtered, non-cached version of wp_upload_dir() that doesn’t check the path. |
get_rest_url()wp-includes/rest-api.php | Retrieves the URL to a REST endpoint on a site. |
get_post_embed_url()wp-includes/embed.php | Retrieves the URL to embed a specific post in an iframe. |
_upgrade_422_remove_genericons()wp-admin/includes/update-core.php | Cleans up Genericons example files. |
network_step2()wp-admin/includes/network.php | Prints step 2 for Network installation process. |
Core_Upgrader::upgrade()wp-admin/includes/class-core-upgrader.php | Upgrades WordPress core. |
Theme_Upgrader::delete_old_theme()wp-admin/includes/class-theme-upgrader.php | Deletes the old theme during an upgrade. |
Plugin_Upgrader::check_package()wp-admin/includes/class-plugin-upgrader.php | Checks that the source package contains a valid plugin. |
Plugin_Upgrader::delete_old_plugin()wp-admin/includes/class-plugin-upgrader.php | Deletes the old plugin during an upgrade. |
Theme_Upgrader::check_package()wp-admin/includes/class-theme-upgrader.php | Checks that the package source contains a valid theme. |
WP_Upgrader::install_package()wp-admin/includes/class-wp-upgrader.php | Install a package. |
WP_Filesystem_SSH2::dirlist()wp-admin/includes/class-wp-filesystem-ssh2.php | Gets details for files in a directory or a specific file. |
WP_Filesystem_SSH2::cwd()wp-admin/includes/class-wp-filesystem-ssh2.php | Gets the current working directory. |
delete_theme()wp-admin/includes/theme.php | Removes a theme. |
WP_Filesystem_FTPext::is_dir()wp-admin/includes/class-wp-filesystem-ftpext.php | Checks if resource is a directory. |
WP_Filesystem_FTPext::dirlist()wp-admin/includes/class-wp-filesystem-ftpext.php | Gets details for files in a directory or a specific file. |
WP_Filesystem_FTPext::cwd()wp-admin/includes/class-wp-filesystem-ftpext.php | Gets the current working directory. |
WP_Filesystem_FTPext::delete()wp-admin/includes/class-wp-filesystem-ftpext.php | Deletes a file or directory. |
WP_Filesystem_Base::find_folder()wp-admin/includes/class-wp-filesystem-base.php | Locates a folder on the remote filesystem. |
WP_Filesystem_Base::search_for_folder()wp-admin/includes/class-wp-filesystem-base.php | Locates a folder on the remote filesystem. |
WP_Filesystem_Direct::dirlist()wp-admin/includes/class-wp-filesystem-direct.php | Gets details for files in a directory or a specific file. |
WP_Filesystem_Direct::delete()wp-admin/includes/class-wp-filesystem-direct.php | Deletes a file or directory. |
WP_Filesystem_Direct::chgrp()wp-admin/includes/class-wp-filesystem-direct.php | Changes the file group. |
WP_Filesystem_Direct::chmod()wp-admin/includes/class-wp-filesystem-direct.php | Changes filesystem permissions. |
delete_plugins()wp-admin/includes/plugin.php | Removes directory and files of a plugin for a list of plugins. |
update_core()wp-admin/includes/update-core.php | Upgrades the core of WordPress. |
WP_Filesystem_ftpsockets::dirlist()wp-admin/includes/class-wp-filesystem-ftpsockets.php | Gets details for files in a directory or a specific file. |
WP_Filesystem_ftpsockets::cwd()wp-admin/includes/class-wp-filesystem-ftpsockets.php | Gets the current working directory. |
get_filesystem_method()wp-admin/includes/file.php | Determines which method to use for reading, writing, modifying, or deleting files on the filesystem. |
get_home_path()wp-admin/includes/file.php | Gets the absolute filesystem path to the root of the WordPress installation. |
list_files()wp-admin/includes/file.php | Returns a listing of all files in the specified folder and all subdirectories up to 100 levels deep. |
unzip_file()wp-admin/includes/file.php | Unzips a specified ZIP file to a location on the filesystem via the WordPress Filesystem Abstraction. |
copy_dir()wp-admin/includes/file.php | Copies a directory from one location to another via the WordPress Filesystem Abstraction. |
paginate_links()wp-includes/general-template.php | Retrieves paginated links for archive post pages. |
WP_Theme::scandir()wp-includes/class-wp-theme.php | Scans a directory for files of a certain extension. |
wp_old_slug_redirect()wp-includes/query.php | Redirect old slugs to the correct permalink. |
get_temp_dir()wp-includes/functions.php | Determines a writable directory for temporary files. |
wp_unique_filename()wp-includes/functions.php | Gets a filename that is sanitized and unique for the given directory. |
get_comments_pagenum_link()wp-includes/link-template.php | Retrieves the comments page number link. |
paginate_comments_links()wp-includes/link-template.php | Displays or retrieves pagination links for the comments on the current post. |
get_pagenum_link()wp-includes/link-template.php | Retrieves the link for a page number. |
get_post_type_archive_feed_link()wp-includes/link-template.php | Retrieves the permalink for a post type archive feed. |
get_term_feed_link()wp-includes/link-template.php | Retrieves the feed link for a term. |
get_search_feed_link()wp-includes/link-template.php | Retrieves the permalink for the search results feed. |
get_post_comments_feed_link()wp-includes/link-template.php | Retrieves the permalink for the post comments feed. |
get_author_feed_link()wp-includes/link-template.php | Retrieves the feed link for a given author. |
get_attachment_link()wp-includes/link-template.php | Retrieves the permalink for an attachment. |
user_trailingslashit()wp-includes/link-template.php | Retrieves a trailing-slashed string if the site is set for adding trailing slashes. |
WP_Admin_Bar::initialize()wp-includes/class-wp-admin-bar.php | Initializes the admin bar. |
WP_Image_Editor::get_output_format()wp-includes/class-wp-image-editor.php | Returns preferred mime-type and extension based on provided file’s extension and mime, or current file’s extension and mime. |
WP_Image_Editor::generate_filename()wp-includes/class-wp-image-editor.php | Builds an output filename based on current file, and adding proper suffix |
plugin_dir_path()wp-includes/plugin.php | Get the filesystem directory path (with trailing slash) for the plugin __FILE__ passed in. |
plugin_dir_url()wp-includes/plugin.php | Get the URL directory path (with trailing slash) for the plugin __FILE__ passed in. |
_wp_link_page()wp-includes/post-template.php | Helper function for wp_link_pages() . |
wp_get_attachment_url()wp-includes/post.php | Retrieves the URL for an attachment. |
WP_Rewrite::mod_rewrite_rules()wp-includes/class-wp-rewrite.php | Retrieves mod_rewrite-formatted rewrite rules to write to .htaccess. |
url_to_postid()wp-includes/rewrite.php | Examines a URL and try to determine the post ID it represents. |
redirect_canonical()wp-includes/canonical.php | Redirects incoming links to the proper URL based on the site url. |
redirect_guess_404_permalink()wp-includes/canonical.php | Attempts to guess the correct URL for a 404 request based on query vars. |
domain_exists()wp-includes/ms-functions.php | Checks whether a site name is already taken. |
get_trackback_url()wp-includes/comment-template.php | Retrieves the current post’s trackback URL. |
comments_template()wp-includes/comment-template.php | Loads the comment template specified in $file. |
get_comment_link()wp-includes/comment-template.php | Retrieves the link to a given comment. |
weblog_ping()wp-includes/comment.php | Sends a pingback. |
_WP_Editors::editor_settings()wp-includes/class-wp-editor.php |
Changelog
Version | Description |
---|---|
1.2.0 | Introduced. |
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