hovercraft icon indicating copy to clipboard operation
hovercraft copied to clipboard

`home_url()` and `get_home_url()` should be called with `'/'` argument

Open siliconforks opened this issue 2 years ago • 1 comments

There are a few places in the code where home_url() and get_home_url() are called without any arguments. These should be home_url( '/' ) and get_home_url( null, '/' ) respectively (or for simplicity just use home_url( '/' ) everywhere).

Calling home_url() or get_home_url() without arguments will output a URL without a trailing slash. For most WordPress sites this will not actually make any difference, but for sites where WordPress is installed in a subdirectory, the result will be a URL that looks like https://example.com/example - this will issue a 301 redirect to https://example.com/example/ instead of rendering the home page directly.

See https://github.com/Automattic/_s/blob/master/header.php for an example of using home_url( '/' ).

siliconforks avatar Oct 07 '23 13:10 siliconforks

Sounds like good info, thanks @siliconforks

Just need to hunt down these instances and make sure we don't forget any of them.

jessuppi avatar Oct 16 '23 22:10 jessuppi