Update: this tool does not work anymore due to Disqus’ export format change (GDPR), which removed commenter’s IP address and Email.
I had been using Ghost on 2015 ~ 2017. It’s a good blogging-platform, but it doesn’t have a built-in comment system, so I had to use a third-party comment service, which is Disqus.
Disqus isn’t a bad platform, in fact, I think it’s a great solution for those who doesn’t want to spend a lot of time investigating how to avoid spams or maintaining. At the same time, it has some great features like “Real time comments” or voting.
Except the loading speed.
Disqus made 38 requests (1.3 MB) to load a thread that only has one comment.
Early this year, I decided to migrate from Hugo to WordPress. WordPress does have a native comment system, so I thought it would be great to use it.
There’s a official WordPress – Disqus plugin, and it has sync comment feature. The problem is, that function only works if the post was initially created with WordPress, so the plugin can associate Disqus Thread ID with WordPress internal post ID.
But that’s not my case, so I decided to create a script to migrate Disqus comments to WordPress.
- Transform Disqus Exported Comments from XML format to JSON, using nashwaan/xml-js
- Render page
- From JSON to SQL command.
- Disqus Exported Comments (Community -> Export)
- Be able to execute SQL command on your database (Using tools like PHPMyAdmin or Adminer)
When you get Disqus Exported Comments head to disqus2wp and select it. (The file won’t be uploaded to anywhere, everything is done locally.)
Once the page finished processing XML, it will append a “Config” card, which has two sections:
This option lets you choose which post’s comment you’d like to import.
It’s necessary to know respective post ID from your WordPress blog.
- Table Name: Where you have your WordPress comments stored. By default, it’s
- Auto Increment: Same as
AUTO_INCREMENTin MySQL. By default, it’s
1. If you have more comments on your database already, find the latest one, and introduce it’s ID + 1
- Admin Email: This function is aimed to single-user WordPress site. If the script find comment made by a user with admin email, it will be imported as a comment created by user
1, which should be the admin of site.
- Transform comment content from HTML to Markdown: Personally, I don’t like those HTML tags from comment. Disabled by default.
Then click the button, and on the right side should appear a bunch of codes. Copy and run them on your database.
Fix Comment Count
You will notice that comment count of each post after import is not updated. Well, this tool doesn’t handle that (yet).
You can fix it by following this post from WPBeginner: How to Fix Category and Comment Count After WordPress Import