Gatsby and WordPress: Creating WordPress Page Types

WordPress Pages are another Post Type, they differ from Post Post(!) Types insofar that they aren’t time-related or be assigned categories and tags. Generally, they’re used for navigational items like About, Contact or Archive pages.

We’re going to update our gatsby-node.js to also pull in WordPress Pages so we can add an About link in our footer.

  const createWpPages = new Promise((resolve, reject) => {
    const query = graphql(`
        allWordpressPage {
          edges {
            node {

    query.then(result => {
      if (result.errors) {

      const pageEdges =
      pageEdges.forEach(edge => {
          path: `/${edge.node.slug}`,
          component: path.resolve(`./src/templates/page.js`),
          context: {

    }) // query.then
  }) // createWpPages

  return Promise.all([createWpPosts, createWpPages])
} // createPages

It’s almost identical to our createWpPosts bar a few places such as query and template.

Here’s the page template src/templates/pages.js

import React from 'react'
import { graphql } from 'gatsby'
import Layout from '../components/layout'

export default ({ data }) => {
  const page = data.wordpressPage
  return (
        <h1 dangerouslySetInnerHTML=&#123;&#123; __html: page.title &#124;&#124; />
        <div dangerouslySetInnerHTML=&#123;&#123; __html: page.content &#124;&#124; />

export const pageQuery = graphql`
  query($id: String!) {
    wordpressPage(id: { eq: $id }) {

Finally, let’s update our footer (which lives in the Layout component src/components/layout.js)

© 2018, Built with <a href="">Gatsby</a> | <a href="/about">About Us</a>

Checkpoint: Let’s talk about us

If we restart Gatsby, and we’ll see a new link in our site footer.

About Link

Clicking on it takes us to our newly created WordPress Page!

About Page

If you got stuck, you can check out the following Git hash: ce6cc022a881e813af31279ff857f908ecc599f4

The Gatsby x WordPress Blog Post series