How to bulk edit a load of URL's in Wordpress?

Man of Honour
Joined
12 Jan 2003
Posts
20,567
Location
UK
Hi everyone, looking for some advice if possible.

I have a Wordpress site with a load of external links at the moment for a certain affiliate programme. They all begin with the same URL prefix (https://www.abcde.com/ for example) but the rest of each link is different as it links to the given product. I need to bulk edit all of these links across my Wordpress site if possible, to move to a different affiliate link partner. Unfortunately the new URL structure is different so i can't simply replace the prefix section and leave the rest as it is, i need to basically remove all those links.

What i'd like to be able to do is search for all links that begin with that prefix, regardless of the rest of the URL, and replace all of them with a single URL that is the same, but from the new affiliate system.

I have tried some plugins search as "better search and replace" but they all seem to lack the ability to find any URL starting with X, they will only find literally just the text you enter and replace that. but while each of these links starts the same, they are all different overall

any suggestions or advice?
 
Soldato
Joined
3 Jun 2005
Posts
3,065
Location
The South
If you've got DB access then you could do a regex replace on the anchor tags within pages/posts (forgotten the table name WP uses for posts) using regex like (https://regex101.com/r/cM8K7z/1) -
Code:
/https:\/\/www\.abcde\.com\/.+(?=")/g

Can't say i've had or tried to do this and i don't doubt there is a "proper" Wordpress solution but as i'm not a massive fan of WP this would be the sledge hammer approach i would use :cry:
 
Soldato
Joined
3 Jun 2005
Posts
3,065
Location
The South
Soldato
Joined
24 May 2006
Posts
3,828
Location
Surrey - UK
Export, tweak, import. You can possibly do this in MySQL, but it's probably quicker and easier to export it, open it up in an editor with regex support, regex replace what you need and import.

On a secondary/staging/test database first, verify your adjusted data works before you potentially fudge your live site.
 
Back
Top Bottom