Last year I also faced this issue on my office site iledscreen. But apply the below technique and now working fine. You can also achieve this by using the preg_replace
function in PHP. Here is an example code:
<?php
$content = 'your content here';
$pattern = '~\/my-profile\/\?uid=(\d+)~';
$replacement = '/myprofile-it/?uid=$1';
$new_content = preg_replace($pattern, $replacement, $content);
In this code, $content
is the page content where you want to replace the links. $pattern
is a regular expression that matches the links that you want to replace. $replacement
is the new link format that you want to replace with. Finally, $new_content
will contain the content with the updated links.
You can add this code to your functions.php
file and call it whenever you want to update the links.
-
This reply was modified 1 year, 2 months ago by bcworkz. Reason: code format fixed
Thanks bellecaroline for the suggested code, but it doesn’t actually do anything in functions.php as shown. It looks like it is intended to be used within a callback to “the_content” filter. That can work, but it needs to be run every time a page is requested.
antobari81, if you would like these changes to be made permanent, it’d be better to actually update the pages in the DB instead of patching up the links on every request. Do you want all links like that anywhere on your site to be updated? If so, I recommend using the Better Search and Replace plugin to update the entire DB.