0

I inherited a Wordpress site and moved it to a new domain. Now there are images that are being sourced from the old domain. How can I update the whole site so that everything uses the new domain?

I already changed "WordPress Address (URL)" and "Site Address (URL)" under Settings. That didn't fix the images.

I found this that says to do a mysqldump and find and replace strings in the SQL file. That seems very hacky and I would be amazed if that were the best solution.

I also found this which also seems to just do a find and replace on a SQL dump.

Is there not a proper, official solution to this that's part of Wordpress itself?

I'm running the site on a plain Debian server, so I have no hosting or access restrictions. Solutions that involve Linux command line tools are not a problem.

1
  • WordPress uses serialized data which can be tricky to replace via SQL itself. Look for a plugin called "Better Search and Replace" and use that to go through your DB tables and replace the URLs for you. Commented Apr 24 at 19:08

1 Answer 1

0

Image URLs in the post content aren't affected by the "WordPress Address" and "Site Address" settings. They're part of the text of the post, rather than something that's generated using those settings. If you've moved to a new domain, you'll need to change these URLs.

If you're comfortable using the command line, I recommend installing wp-cli (if you haven't already) and then using its powerful search-replace command. I always do a dry run of any search-replace command first, to make sure I'll see the results I expect.

wp search-replace --dry-run https://old-domain.com/ https://new-domain.com/ --report-changed-only

...and then, if I'm satisfied it's going to replace the strings I need it to replace (and, crucially, only the strings I need replaced)...

wp search-replace https://old-domain.com/ https://new-domain.com/ --report-changed-only

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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