1

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!

0

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() );
0
0

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); 

See https://www.php.net/manual/en/function.str-replace.php.

1
  • Thank you very much! I want to display the url under the current article. – William Apr 11 '19 at 1:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.