For example, the current url is:
I want to display this url under the showing article and also change the domain to:
Is there any way to do this?
Thank you guys a lot!
For example, the current url is:
https://example1/hello-world
I want to display this url under the showing article and also change the domain to:
https://newdomain/hello-world
Is there any way to do this?
Thank you guys a lot!
Share Improve this question edited Apr 11, 2019 at 1:50 William asked Apr 11, 2019 at 1:39 WilliamWilliam 151 silver badge5 bronze badges2 Answers
Reset to default 0If it’s a page or post, then you can get its url with get_permalink()
.
And to change the domain, you can do some simple string replacing with str_replace
.
So here’s the code:
echo str_replace( 'OLD_DOMAIN', 'NEW DOMAIN', get_permalink() );
A simple PHP str_replace()
ought to do it. Although you don't mention where (or even why) you need this.
$oldstring = "https://www.example/here/there/";
$search_for = "example";
$replace_it = "newdomain";
$newstring = str_replace($search_for, $replae_it, $oldstring);
See https://www.php/manual/en/function.str-replace.php.