Fix Broken Image Links After WordPress Migration
In this article
After migrating a WordPress site, images may not display correctly due to broken links. This guide will help you identify and fix these issues so your site looks and functions as intended. You'll learn how to use tools and manual methods to ensure all image links point to the correct new location. Before beginning, you may need access to your site's database and file system.
What You'll Need
- FTP or cPanel access to your hosting account
- Access to the WordPress database via phpMyAdmin or a database tool
- A search and replace tool for databases
- Basic knowledge of how to edit files or use a code editor
- Administrator access to your WordPress site
Step-by-Step
- Identify Broken Images
Visit your website and look for missing images. You can do this by checking the website manually or using a plugin like Broken Link Checker to find missing images automatically.
- Search the Database for Old URLs
Open your WordPress database via phpMyAdmin. Look for the following tables: wp_posts, wp_postmeta, and wp_options (change 'wp' to your table prefix if it's different). Search for entries containing the old domain or file path.
- Use a Safe Search-and-Replace Tool
Use a search-and-replace tool (like Interconnectit's Search and Replace or Better Search Replace plugin) to replace all instances of the old URL with the new one. Make sure the tool is set to properly handle serialized data to avoid corrupting the database.
- Check Media Library Paths
Log into your WordPress admin and navigate to Media > Library. Click on each image and verify that the URL matches your new site's domain. If not, update the URL manually or via a plugin like Velvet Blues Update URLs.
- Verify Posts and Pages
Go through your site's posts and pages to ensure that all embedded images are now functioning correctly. If an image still doesn't show up, check the source code of the post to see if the URL is correct.
- Clear Caches
Clear your site's cache using your caching plugin or hosting provider's tools. If you're using a CDN, clear it too to ensure visitors see the updated site immediately.
Common Mistakes
One common mistake is skipping the step to update URLs in the database. Many people only update the Media Library and overlook database entries. Another is using a basic search-and-replace tool that doesn't handle serialized data, which can break your site. Also, forgetting to update URLs in widget areas or custom fields can leave some images broken.
Tips
Always back up your site before making changes to the database or files. Use a staging site if possible to test changes before applying them to the live site. Consider using a migration plugin like Duplicator or All-in-One WP Migration next time to avoid many of these issues. Lastly, keep your URLs simple and consistent across your site to minimize migration issues.
Troubleshooting
If images still don't display after following the steps, check if the image files actually exist in the new media directory. If they’re missing, you may have forgotten to transfer them during migration. You can do this via FTP or cPanel. If URLs look correct but images don't load, there may be a permissions issue or a problem with file types. Check the site's error logs via your hosting control panel to get more clues.
Frequently Asked Questions
Why do images still show as broken after migration?
Old URLs may still be stored in the database or file paths may be incorrect. Double-check your database entries and ensure all files were transferred correctly.
Can I use a plugin to fix image URLs?
Yes, plugins like Better Search Replace or Velvet Blues Update URLs can automate the process of updating image URLs after migration.
What if I don't have access to phpMyAdmin?
You can use a plugin like Better Search Replace to update URLs in the database without needing direct access. Always back up your site before making changes.
Do I need to update old URLs in every post?
Not manually. Use a search-and-replace tool to update all URLs at once. Only manually check if images still appear broken after using the tool.
Will this affect SEO?
Broken images can negatively impact SEO. Fixing them improves user experience and helps maintain your site's ranking. Use proper redirects if you've moved image URLs permanently.
Can I recover a missing image from a backup?
Yes, if you have a pre-migration backup, you can restore the image file from there. Upload it to the new site’s media library and update the URL in the post or page where it appears.