Removing the https:// from a URL field

Is there a way of removing the https:// and trailing / from a URL field?

In php (ACF) I do this:

$website = get_field(‘website’);
$website_nice = parse_url( $website, PHP_URL_HOST );

Wondering if there’s something that will do the same thing in L&L?

I have tried the Format tag which works great but it still retains the trailing / which the php code removes.
<Format replace="https://" with=""><Field website /></Format>

Hi there!
Unfortunately, there isn’t any possible way to do this but I will send a feature request to the devs and I’ll let you know when the feature is available!

Thanks Emma! Appreciate the referral to the devs and looking forward to to seeing what they come up with.

You can remove the trailing / by setting a custom permalink structure in WP without trailing /.

See Settings → Permalinks

1 Like

Thank you but it’s an external link entered into an ACF field, not a page on the site.

Hi Tracey, we’re scoping out some more powerful regex-based format replace options so I’ll try to keep you posted here when those get released, but I’m not sure what the timeline is. I spoke to a dev and he mentioned that since you’re comparing the functionality you want to PHP_URL_HOST, that means that no slashes can be inside a host. I know on Facebook you mentioned that you “don’t want to replace the slash in case there are others in the URL” but it sounds like if there are other slashes in the URL then even PHP_URL_HOST wouldn’t work. I’m not familiar with PHP_URL_HOST myself but I figured I’d pass along my understanding of the insights the dev shared.

So all that to say, it sounds like you should be safe to remove all slashes with:

<Format replace="https://" with="" replace_2="/" with_2=""><Field website /></Format>

I’ll still try to update this thread when we implement some more flexible options for L&L’s search-replace functionality.

Thanks Benjamin.

Sounds complex! Hope you figure out an answer. I’ll have to check my links using the PHP_URL_HOST to see if they are broken.

@TraceElement I just realized that it should actually be possible to remove the trailing slash in L&L even in instances where your URL includes other slashes. I was checking out the length attribute for the Format tag and I noticed it said this underneath:

It uses PHP’s mb_substr function

Clicking on that link made me realize that this seems to accept negative numbers so I tried it and sure enough, if you use something like length=-5, it’ll chop off the last five characters. So in your case, you could probably do something like this if your URLs are always going to end in a slash:

<Format replace="https://" with="" length=-1><Field website /></Format>

And if the URLs only sometimes end in a slash, you could try something like this:

<Format replace="https://" with="">
  <If field=website ends_with value="/">
    <Format length="-1"><Field website /></Format>
    <Else />
    <Field website />

In the newest version of L&L, the Format tag has an attribute start_slash and end_slash to add/remove a slash at the start/end.

 <Format replace="https://" with=""><Format end_slash=false><Field website /></Format></Format>

Amazing! Thank you so much!

1 Like