---
title: Fix images pointing to localhost after a move
url: https://wp2wp.link/guides/fix-localhost-urls-after-migration
language: en
updated: 2026-11-23
publisher: wp2wp.link
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language questions, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://wp2wp.link/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://wp2wp.link/agents"
---

# Images and links still pointing to localhost after a migration

The database still holds the old `localhost` or `.local` address. Replace it with Better Search Replace or `wp search-replace`, never with a plain text replace, then clear every cache.

By [wp2wp.link](https://wp2wp.link/guides/about) · Updated 23 November 2026 · 4 min read

- Result: Links and images use your domain
- You need: Admin login or SSH
- Cost: Free
- Do first: Back up the database

## Which way fits you?

- With a plugin: Better Search Replace, from the dashboard. No SSH needed.
- With WP-CLI: One command over SSH. For people who use the command line.
- Not moved yet: Copy with wp2wp.link, and links point to your domain afterwards.

## Before you start

- A fresh database backup, for example with `wp db export before-replace.sql`.
- The old address exactly as the site used it, such as `http://localhost:8881`.
- Your new address, such as `https://example.com`.

Never replace in the SQL file: serialized data stores the length of each text, as in `s:21:"http://localhost:8881"`. If you change the address in a text editor, the length no longer matches. Then WordPress drops the value without a warning. Widgets vanish, theme settings reset, and page builders show empty pages. The tools on this page fix the lengths while they replace.

## With a plugin

The free Better Search Replace plugin does the replace from the dashboard. Its dry run shows what would change, without changing anything.

1. Under **Plugins → Add New Plugin**, install Better Search Replace.
2. Under **Tools → Better Search Replace**, enter the old address and your new one.
3. Select all tables and run a dry run first.It shows how many entries would change.
4. If the count looks right, run it again without the dry run.
5. Repeat for every variant of the old address you find.For example `http://mysite.local`, the address with a sub-folder, or the escaped form `http:\/\/localhost:8881` inside JSON.
6. Clear your caching plugin, then the CDN if you use one.
7. Remove the plugin.

## With WP-CLI

With SSH at your hosting, `wp search-replace` does the same in one command.

1. Try the replace as a dry run first.`wp search-replace 'http://localhost:8881' 'https://example.com' --all-tables --dry-run`
2. If the count looks right, run it again without `--dry-run`.
3. Repeat for every variant of the old address you find.For example `http://mysite.local`, the address with a sub-folder, or `http:\/\/localhost:8881` inside JSON.
4. Flush the cache with `wp cache flush`.Then clear your caching plugin, and the CDN if you use one.

## Not moved yet?

If you move the site with wp2wp.link, links and images point to your new address afterwards, so you can skip the replace.

- Links written as plain text, for example in a privacy policy, are left as they are.
- A site that moves from a sub-folder to the domain itself may still need the path replaced with the steps on this page.

## How you know it worked

- A new dry run for the old address finds nothing.
- Pages and images load from your domain, also after clearing the caches.
- You can log in at `/wp-admin` without being sent to localhost.
- Widgets, theme settings and builder pages look as before.

## If something goes wrong

### The login redirects to localhost

The cause is `siteurl` or `home` in `wp_options`, or `WP_HOME` / `WP_SITEURL` in wp-config.php. Set `WP_HOME` and `WP_SITEURL` to your domain in wp-config.php and log in. Then run the full replace.

### Images are broken, links work

Page builder data or CSS files still hold the old address. Regenerate the builder’s CSS in its settings.

### The address is fixed, but the page still shows it

A cache serves the old page: a caching plugin, the host’s cache or a CDN. Clear each of them.

### The browser warns about mixed content

Your `https://` site still has `http://` links. Replace the `http://` form of your address too.

### The sub-folder is still in the links

The site moved from `localhost/mysite` to the domain itself. Replace the whole old address, including the folder.

## Questions

### Where does WordPress keep the old address?

In the database table wp_options: siteurl, home, and widget, theme and plugin settings. In wp_posts: content, block attributes and GUIDs. Also in wp_postmeta: page builder data from Elementor, Divi or Beaver Builder and custom fields, often as JSON or serialized arrays. CSS files that themes and plugins create with full addresses can hold it too.

### Do I need to change the GUIDs?

On a site that was already public, WordPress advises against it, because feed readers use the GUIDs. If the site was never public, you can replace them too.

Moving a site from your computer? wp2wp.link copies it, and afterwards the links point to your domain.

[Start your move](https://wp2wp.link/#migrate)Free · No account

### Sources, checked 18 November 2026

[WP-CLI search-replace](https://developer.wordpress.org/cli/commands/search-replace/), [Better Search Replace](https://wordpress.org/plugins/better-search-replace/), [WordPress: Moving WordPress](https://developer.wordpress.org/advanced-administration/upgrade/migrating/), [Reprint](https://wordpress.org/plugins/reprint/), [Reprint limitations](https://github.com/WordPress/reprint/blob/trunk/docs/handbook/limitations.md).

## Related guides

- [Move a local WordPress site to a live server](https://wp2wp.link/guides/local-wordpress-to-live-server)
- [XAMPP and MAMP to live](https://wp2wp.link/guides/xampp-mamp-wordpress-to-live)
- [Migrate WordPress to a new host](https://wp2wp.link/guides/migrate-wordpress-to-new-host)
