最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

permalinks - How to get the full URL of the current page and change domain of it?

matteradmin6PV0评论

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 badges
Add a comment  | 

2 Answers 2

Reset to default 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() );

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.

Post a comment

comment list (0)

  1. No comments so far