I have a wordpress website with a banner link showing as below:
<a href="<?php echo site_url(); ?>" >Banner</a>
And this will return a result as: http://example.com
What I want is to let the site_url have a trailing slash, so the address would look like http://example.com/
So my question, is it okay to concatenate the site_url() with a trailing slash like this?
<a href="<?php echo site_url() . '/'; ?>" >Banner</a>
Yes, what you are did is Ok. But I have a little different solution weather it contains trailing slash or not just add it like this.
$url = site_url();
echo rtrim($url ,"/").'/';
接受的答案有效,但如果您想要完整的 WP 解决方案,请使用trailingslashit()
:
$url = trailingslashit( site_url() );
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.