Viewing 7 replies - 1 through 7 (of 7 total)
  • home_url is a WordPress funktion. You can use trailingslashit to solve your problem.

    Thread Starter Nikita_Sp

    (@nikitasp)

    @codestylist it’s not the solution. I know that it’s WP function, but:

    1) Default WordPress HAS NO translated static homepage and the plugin should add some hooks or filters to make home_url function return correct homepage url on certain languages – so it’s plugin question.

    2) If you read my first message more carefully you’ll see that the default website url is https://example.com, and if I use trailingslashit I’ll get https://example.com/ – and there will be redirect that I want to avoid.

    • This reply was modified 4 years, 7 months ago by Nikita_Sp.
    • This reply was modified 4 years, 7 months ago by Nikita_Sp.
    Plugin Author Chouby

    (@chouby)

    Hello,

    home_url() returns without slash as expected. If you want a slash, use home_url( '/' ).

    Thread Starter Nikita_Sp

    (@nikitasp)

    @chouby yeah, I know, but the thing is:
    1) default site url without / – so it shouldn’t be in the link
    2) other languages static home page has url like /cz/ but the link returned without /.

    I mean there is a redirect from https://example.com/cz to https://example.com/cz/ and it’s right, but the function seems should return url also with / as a canonical url of the homepage to prevent redirects, no?

    Of course I can use this:
    <a href="<?php echo home_url(); ?><?php if ($language != "main_lang_code") { ?>/<?php } ?>">home</a>

    but it seems a little bit… shittycode ??

    Thread Starter Nikita_Sp

    (@nikitasp)

    @chouby hi!
    Any ideas?

    Plugin Author Chouby

    (@chouby)

    Did you test home_url( '/' ) ?

    Thread Starter Nikita_Sp

    (@nikitasp)

    @chouby did you read my message?
    home_url('/') adds slash for any page – I don’t need it on the home page with default language.

    The main thing is that homepage got url without / and translated homepage got url WITH / on the end, but home_url() always return or with / or without it.

    Example:
    example.com – it’s homepage url, home_url() returns this address
    example.com/ch/ – it’s Chinese language homepage page url and home_url returns example.com/ch – why?

    If I use home_url(‘/’), than i’ll get example.com/ instead of example.com for the main language page.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘home_url() returns url without slash in the end’ is closed to new replies.