wordpress - Get current URL with PHP and change a part of it for a new url
Get the solution ↓↓↓I am working on a WordPress website for a client. I want to create a switch element through a current URL change. For instance;
https://mywebsite.com/shop/CUSTOMER should change to https://mywebsite.com/shop/OWNER
echo $ _SERVER ['REQUEST_URI']; ?>
I have found a php code that provides me the URL of the current page. So if the visitor is on the /shop/customer page, I've found a way to create a shortcode and add my own string to it. But it creates a new link like; /shop/customer/owner
I want to replace customer in owner, not adding owner to the current link. Because it has to be a dynamic solution. For example, if the visitor is on https://mywebsite.com/shoppingcart/customer, they should change this to https://mywebsite.com/shoppingcart/owner
Sorry for the bad english, hope you understand what i need.
Regards, Rick
Answer
Solution:
May be this could work!
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$change_url = str_replace("customer","shopping",$actual_link);
echo $change_url;
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: the requested url was not found on this server. xampp
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.