简体   繁体   中英

Why does the trailing slash appear after url when using home_url() in Wordpress?

Example: when the home_url() function is used to fill the value for the href attr in a tag, for example the name of the site:

<h1><a href="<?php echo home_url(); ?>">
        <?php bloginfo('name'); ?></a>
</h1>

With no $path parameter added to the function ('/') how does the trailing slash end up in the url after the link is clicked?

In the database, in the "home" record(wp_options table) there is no trailing slash at the end of the url: http://localhost/wordpress .
So, what's going on?

Seems like a piece of functionality they asked for and implemented as a feature request:

https://core.trac.wordpress.org/ticket/13245

A quick fix would be to rtrim the slash character:

<h1><a href="<?php echo rtrim(home_url(), '/'); ?>">

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM