For example, the current url is:
https://example1.com/hello-world
I want to display this url under the showing article and also change the domain to:
https://newdomain.com/hello-world
Is there any way to do this?
Thank you guys a lot!
If 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.com/here/there/";
$search_for = "example.com";
$replace_it = "newdomain.com";
$newstring = str_replace($search_for, $replae_it, $oldstring);