[wp-hackers] user_trailingslashit()?

Andrew Nacin anacin at gwhatchet.com
Tue Dec 8 06:29:50 UTC 2009

> Maybe I'm just confused by some carelessly written code?  For example, why
> do this?
> $link = trailingslashit(get_bloginfo('home')) . str_replace('%pagename%',
> $post_type['plural'] . '/' . $post->post_name, $permastruct);
> $link = user_trailingslashit($link);

It's actually carefully written code. In this example, 'home' is
trailing-slashed. (Certain options are always without a slash -- xref:
get_option()) Then, dependent on the user's permalink setting, the entire
link gets a trailing slash.

Why not just:
> $link =user_trailingslashit(get_bloginfo('home')) .
> str_replace('%pagename%', $post_type['plural'] . '/' . $post->post_name,
> $permastruct);

This is incorrect code. Here, you're misapplying user_trailingslashit, which
is for whether a permalink structure calls for a slash at the end.
get_bloginfo('home') will not return a trailing slash and will need one, but
here, it will only be given one if the permalink structure calls for one.
(And then the user's permalink structure is ignored as to whether a trailing
slash is desired -- I think you get the picture.)

More information about the wp-hackers mailing list