Skip to content
Migrate WordPress posts to Contentful using the WP REST API and the Contentful JS SDK.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

WordPress to Contentful

Migrate WordPress posts to Contentful using the WP REST API and the Contentful JS SDK.

  • Markdown: Post bodies are converted to Markdown to strip out inline styles and image dimensions.
  • Assets: Featured and inline images will be transferred and their references in content replaced.
  • Authors: Script looks for CF Person names that match WP User and reassign author attribution.
  • Date Published: Preserved

🚀 Usage

  1. Prerequisites
  2. yarn install
  3. yarn start

⚠️ Prerequisites


Make sure to temporarily disable any publish webhooks (e.g. Netlify) because this is gonna do a lot of publishing.

Globally installed

Contentful Content Types

Assumes the following content types are already created in Contentful:

Person: person

For best results, create Persons with matching names so posts authors in the two systems can be matched up and attributions preserved. Otherwise, the fallback Person ID will be used.

Blog Post: blogPost

See fields in source

Contentful Content Management API

Contentful CMA tokens have access to all environments for migration purposes so make sure to double-check the relevant config var to see which is being targeted.

WP Users API route

The /wp-json/wp/v2/users should return a paginated list of users, if it does not and returns an error like the one below (via Wordfence) it will need to be enabled before the author tasks can run effectively:

  "code": "rest_user_cannot_view",
  "message": "Sorry, you are not allowed to list users.",
  "data": {
    "status": 401

⚙️ Config

Values required for all of the variables below, or the test config (first) task will throw.

# Base URL for API requests

# WP returns absolute URLS, we use relative

# Generated in web app interface

# Go to Project's Settings > General Settings

# Sandbox environment name, or master

# Default locale (in my case "en-US")

# "Person" ID used when a match cant be found
# comparing WP User to CF Person names (post
# author attribution)

🙏 Cite

Lots of inspiration from this article and linked gists, it inspired the general approach and some of the of code is used directly.

☑️ Goals

  • Replace Listr with Ink static & dynamic logging
  • Optional, incremental steps
  • Multi-phase approach
    1. Migrate content to sandbox env
    2. Export structure/content using CF Migration CLI
    3. Use CF tooling to migrate content into master
You can’t perform that action at this time.