Site hosting news, tutorials, tips, How Tos and more

How to fix broken images and links in a WordPress site

howtoBroken image links are a common problem when you move your WordPress installation to another domain name or even to another subfolder. WordPress uses absolute paths to link images and objects to the page. The absolute path is usually defined during the initial WordPress setup process when you first configure WordPress. No problem right? You understand and know what absolute paths mean, and WordPress is working with no problems.

But what happens when you change the domain name for your WordPress site, or you move your WordPress site to a subfolder? Now you call on your WordPress site and some links are broken, images don’t show up, or some of the pages may come up with a 404 not found error. You right click on an image or object on the page and you can see the URL address does not match with the URL address on the address bar.

What a mess. Now what?

Fear not, this is actually a fairly easy fix!

There are a few easy way to fix this. The first thing to try is logging in to the WordPress admin section and changing the values in Settings > General.  But sometimes the location change can make logging in to the admin section impossible, in which case you’ll want to try setting the new URL by either defining the SiteURL and Home variables in your configuration file, or going in to the database and changing them there.

Updating the wp-config.php file

Log into your site via FTP and look for the WordPress wp-config.php file. Open the file with a text manager such as NotePad and add these lines. Typically you should be able to add the lines under the connection string section of the configuration file.

/**Manually Define SiteURL and Home */
define(‘WP_HOME’,’http://www.newdomain.com’);
define(‘WP_SITEURL’,’http://www.newdomain.com’);

If you have just moved the WordPress files to a subfolder then the URL would look somewhat like this.

define(‘WP_HOME’,’http://www.newdomain.com/newsubfolder’);
define(‘WP_SITEURL’,’http://www.newdomain.com/newsubfolder’);

In my opinion, this is actually the easiest way to fix this. But some site owners don’t like to hard code values into the page, so the second way to solve the problem is to update the database. WordPress uses MySQL as it’s back end, and the SiteURL and HOME URL values are stored in there in plain text, so they’re easy to change.

Updating your WordPress database:

Log into your WordPress database. The table you will be looking for is wp_options. wp_ is the default prefix that WordPress will use in the initial setup. You may have used a different DB prefix during set up, but in general what you are looking for is the “Options” table.

Run this SELECT command against the Options table.

USE [Database Name];
SELECT option_name, option_value FROM wp_options
WHERE option_name="home" OR option_name="siteurl";

You should see results similar to this.

option_name option_value
home http://www.olddomain.com
siteurl http://www.olddomain.com

To update the option_value column, just run this command against your database.

USE [Database Name];
UPDATE wp_options
SET option_value="http://www.newdomain.com"
WHERE option_name="siteurl" OR option_name="home";

If you are moving the WordPress site to a subfolder, the option_value would include the path to the subfolder:

SET option_value="http://www.newdomain.com/subdomain"

That should be it. Either method will work. But don’t forget, at Winhost we can migrate your WordPress website for you. We’ll create and restore the MySQL database, update your connection string and make sure the absolute path it setup correctly. Simply contact our Support Department for more details on what we will need to migrate your site for you.

Rate this article
   

One Response
  • Dale Lature Reply

    My WordPress blog doesn’t use absolute paths, and that’s not the default.

Have a comment? Make it here!

This site uses Akismet to reduce spam. Learn how your comment data is processed.