What does the user_trailingslashit()
function do, and when should I use it? How is it different from the trailingslashit()
function?
1 Answer
The trailingslashit()
function adds a /
to the end of a URL if it lacks one.
user_trailingslashit()
uses the permalink template as set under Settings > Permalinks to decide whether to add or remove the trailing slash from the end of the URL
For example, if you had the permalink format set to /%year%/%monthnum%/%day%/%postname%/
(note the trailing slash), user_trailingslashit()
would append a trailing slash to the URL passed in as the first parameter.
If the permalink format was /%year%/%monthnum%/%day%/%postname%
(no trailing slash), any trailing slash on the URL would be stripped off.
Basically, user_trailingslashit()
forces the URL to be consistent with what is set in the permalink preferences.