ChrisP777
ChrisP777

Reputation: 359

forcing a trailing slash at the end of site_url()

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>

Upvotes: 0

Views: 1013

Answers (2)

butlerblog
butlerblog

Reputation: 436

The accepted answer works, but if you want a full WP solution, use trailingslashit():

$url = trailingslashit( site_url() );

Upvotes: 1

A l w a y s S u n n y
A l w a y s S u n n y

Reputation: 38552

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 ,"/").'/';

Upvotes: 1

Related Questions