Migrate custom permalinks as slugs, or vice versa [WordPress]
![Migrate custom permalinks as slugs, or vice versa [WordPress]](img/ogp.webp)
If you are using "Custom Permalinks" to freely set URLs in WordPress
You would enter it in an input field like this, right?

However, I believe that using slugs for URLs is the correct way to begin with.
If you're using Custom Permalinks, aren't you neglecting the slug values?

When migrating such an environment to a new one,
you might have set permalinks using "Custom Permalinks" in the old environment,
but want to set permalinks using "slugs" in the new environment.
I will explain how to do this (or the other way around).
Table of Contents
Check the export file
Select the content from "Tools" > "Export" and "Download Export File".

Then an xml file will be downloaded.
If you open it with an editor and check the contents, you'll see many <item>~</item> tags, each representing an article.
<item>
<title><![CDATA[Hello world!]]></title>
<link>http://test.localhost/news_hello_world</link>
<pubDate>Wed, 21 Dec 2022 07:53:36 +0000</pubDate>
(略)
</item>
<item>
<title><![CDATA[Hello japan!]]></title>
<link>http://test.localhost/news_hello_japan</link>
<pubDate>Wed, 22 Dec 2022 07:53:36 +0000</pubDate>
(略)
</item>
<item>
<title><![CDATA[Hello tokyo!]]></title>
<link>http://test.localhost/news_hello_tokyo</link>
<pubDate>Wed, 23 Dec 2022 07:53:36 +0000</pubDate>
(略)
</item>
If you look closely at one <item>
<item>
<title><![CDATA[Hello world!]]></title>
<link>http://test.localhost/news_hello_world</link>
<pubDate>Wed, 21 Dec 2022 07:53:36 +0000</pubDate>
(略)
<wp:post_name><![CDATA[hello-world]]></wp:post_name>
(略)
<wp:postmeta>
<wp:meta_key><![CDATA[custom_permalink]]></wp:meta_key>
<wp:meta_value><![CDATA[news_hello_world]]></wp:meta_value>
</wp:postmeta>
(略)
</item>
Inside it, this is the "slug"
<wp:post_name><![CDATA[hello-world]]></wp:post_name>
This is set to Custom Permalinks.
<wp:postmeta>
<wp:meta_key><![CDATA[custom_permalink]]></wp:meta_key>
<wp:meta_value><![CDATA[news_hello_world]]></wp:meta_value>
</wp:postmeta>
So, you just need to fix this part for all articles and import them again.
In the opposite case
If you were setting permalinks using "slugs" in the old environment,
but want to set permalinks using "Custom Permalinks" in the new environment,
the Custom Permalinks section will likely be missing from the export data.
You just need to add it inside <item>
<item>
(略)
<wp:postmeta>
<wp:meta_key><![CDATA[custom_permalink]]></wp:meta_key>
<wp:meta_value><![CDATA[Custom Permalinksに入れたい値]]></wp:meta_value>
</wp:postmeta>
</item>
Batch Replace
Here's a simple batch replacement tool I made for myself.
- It runs client-side. No information is acquired.
- The results are not absolute. Please use it after taking a backup.
- Please use difff.jp or similar tools to confirm that only the intended parts have been replaced.
Input
Mode
Result
Advanced Settings
Regular expression for copying Custom Permalinks to slug
Search
Replace
Regular expression for copying slug to Custom Permalinks
Search
Replace
Import
Import the completed xml file into the new environment.

Please make sure to take a backup before proceeding.
Comments
If you found something different in your environment, please feel free to comment.
Key visual : Free material of a woman enjoying a morning smoothie




If this was helpful, we appreciate your support!
All support received will be used for childcare.
Or support us by buying something from the buttons below
(You don't have to buy the linked product.)
Amazon
Rakuten Ichiba
Yahoo! Shopping
PR