What to do if the link to the URL at the top of the site remains the old address when you change the address of the site in WordPress

日本語

The following are the bugs and solutions that occurred in WordPress ver.5.5.1.

At First

If you run a site, you may want to change your site address. For example, when you used the default address on your rental server, but later acquired your own domain. WordPress is designed to make it relatively easy to deal with such situations.

For details on how to change the WordPress address, please refer to the other sites below.

The easiest way to do this is to change the two places in Settings> General “WordPress Address (URL)” and “Site Address (URL)” to new addresses. Now WordPress will automatically generate the link with the new address. The links you insert in the article will have to be modified manually, but the efficient way to do this is an extra.

Address

Problem occurrence and solution

However, despite the above measures, the link to the top page may remain at the old address. Furthermore, if you click the link to the top page, you may get into a redirect loop and get a browser error. It is a big problem if you do not know how to deal with it, so I would like to share the workaround for those who face similar problems.

From Appearance> Customize> Homepage Settings (or Settings> Reading), if the homepage is a static page, change it to latest posts and save it, then return to the static page and save it.

Reasons for problems

Why does the problem mentioned here occur and can be solved by the above method? The following is a guess, but the possible reason for the situation.

WordPress is a type of CMS that programmatically generates and displays pages when there is a request for a page. However, if all the content of the page is generated from 1 each time, the load on the server will inevitably increase. Also, it is inefficient to calculate and output almost the same content each time.

Therefore, it is speculated that WordPress caches some information so that it does not have to be recalculated. I think one of the information is a link to the top page. Then, changing the address of the setting does not update the cache, so the link to the old address remains.

It seems that the cache is updated by switching the setting of the homepage to latest posts or a static page.

Extra

If you change the site address, you will have to manually fix the links in the article. However, finding and fixing links one by one in an article can be too time consuming. In such a case, the correct answer is to use the power of a convenient plug-in.

Plugin Search Regex is a plugin that allows you to search for any string in all articles and replace it with a specific string at once. You can search the old address from all articles and replace it with the new address in an instant.

Search Regex