• Stars
    star
    214
  • Rank 184,028 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Gatsby + WordPress starter for continuous deployment to Netlify

Gatsby

👋 Looking for a way to support live previews with Gatsby + WordPress?

Check this repo out!

Gatsby + Headless WordPress + Netlify Starter

A starter skeleton that leverages the WordPress API for Gatsby. Support for Continuous integration with Netlify. Publishing posts call the Netlify build hook. Deploy to Netlify stage or production enviroment when updating a WordPress post or page.

Dependencies

This Project was forked from the default Gatsby Starter

Production Demo

Stage Demo

Getting Started

  1. Fork Gatsby WordPress Netlify
  2. Clone your forked repository
  3. npm install --global gatsby-cli (if you don't have Gatsby CLI installed)
  4. In the root of your project yarn install
  5. Open your gatsby-config.js file and change the baseUrl to your WordPress url
  6. Run yarn develop -- not gatsby develop

Netlify

Signup for a Netlify account if you don't already have one.

  1. Create a new site
  2. Select "GitHub" from "Continuous Deployment"
  3. Search and select your repository
  4. Click "show advanced"
  5. Click "new variable"
  6. Add a deploy key DEPLOY_ENV with a value of lbn_published_stage
  7. Click "deploy site"
  8. Under Settings > Build & Deploy click "add build hook"
  9. Name something that signifies environment (stage or production)
  10. (Optional) Click "site options" and then "change site name". Rename to something that signifies this is the environment (stage or production).
  11. (Optional) Repeat the process above a second time to create a production environment. Change the DEPLOY_ENV to lbn_published_production Optionally rename accordingly.

Install WordPress

Install WordPress on the server of your choice or use an existing site. I recommend a stripped down theme with no front end like this. For example, this site uses http://gatsbynetliflydemo.justinwhall.com/wp-json/ for its data source. which is no more than a stripped down _s theme.

Install WP Buildhook Deploy plugin (Optional. Can be used without this if you don't care about building on publish.)

  1. Download or clone the WP Buildhook Deploy plugin and install on your source WordPress site.
  2. Find your build hooks on Netlify Settings > Build & Deploy
  3. Add build hooks to your WordPress install under WP Admin > Settings > WP BuildHook Deploy 

Publish!

Support for Gutenberg out of the box. If you are using the classic editor, the default "Publish" metabox has been replaced with:

publish

If you update or publish a post with an environment checked, your post will be published to that environment. Likewise, if you update/publish with an environment unchecked, A post will be removed from that environment. For example, if you uncheck both environments and update, the post will be removed from both. If you publish/update with both environments checked, the post will be published to both.

Example:

Using this starter requires configuring the gatsby-config.js file. You really only need to change BaseUrl, and hostingWPCOM if you're using WP.com rather than WP.org

{
  resolve: 'gatsby-source-wordpress',
  options: {
    // The base url to your WP site.
    baseUrl: 'YOUR_WORDPRESS_URL',
    // WP.com sites set to true, WP.org set to false
    hostingWPCOM: false,
    // The protocol. This can be http or https.
    protocol: 'http',
    // Use 'Advanced Custom Fields' Wordpress plugin
    useACF: true,
    auth: {},
    // Set to true to debug endpoints on 'gatsby build'
    verboseOutput: false
  }
},
  • Update GraphQL queries to match your WordPress Content. This is the query currently on the index page. You either need to add ACF's in your WordPress to match the query (in this case Project and Date), or you need to remove those aspects of the query. The featured_media isn't a problem -- it'll work even if you have posts without featured images.
allWordpressPost {
      edges {
        node {
          featured_media {
            source_url
          }
          author {
            name
            avatar_urls {
              wordpress_24
              wordpress_48
              wordpress_96
            }
          }
          date
          slug
          title
          modified
          excerpt
          id
          acf {
            project
            date
          }
          categories {
            name
          }
          tags {
            name
          }
          content
        }
      }
    }
  • Finally, you'll probably want to update the SiteConfig to match your info, because right now it has mine. 🤠

More Repositories

1

wp-buildhook-deploy

WordPress plugin to trigger build hooks and deploy your static site.
PHP
163
star
2

wordpress-gatsby-preview-starter

A starter for WordPress + Gatsby that supports live previews
JavaScript
85
star
3

directorySlider

jQuery slider that uses all images from a specified directory
JavaScript
42
star
4

ACH-for-stripe-plaid

WordPress plugin that allows easy ACH bank transfer payments via Stripe + Plaid
PHP
17
star
5

r2d2

React WordPress Theme
JavaScript
14
star
6

WordPress-theme-options

Class for WordPress Theme Options Page
JavaScript
7
star
7

littlebot-wordpress-api

Bare bones WordPress theme with no front end to use as an API
CSS
6
star
8

nextjs-serverless-aws

JavaScript
4
star
9

Stripe-Card-Expiration-Reminder

PHP
3
star
10

littlebot-invoices

WordPress plugin that brings estimating and invoicing to your admin dashboard
PHP
1
star
11

nextjs-apollo-wordpress

A headless WordPress + NextJS + Apollo starter
JavaScript
1
star
12

LiteBrite

Dark theme for Textmate or Sublime Text
1
star
13

wp-tel-links

Finds all telephone numbers and replaces them with click-2-call tel links
JavaScript
1
star
14

wordpress-min-image-upload-size

Plugin that provides a way to set minimum image size uploads for posts and custom fields upload inputs
PHP
1
star
15

now-serverless-sendgrid-inbound-parse

Trigger a Now Serverless Lambda with SendGrid Inbound Parse then send a SMS with Twilio
JavaScript
1
star
16

justinwhall-frontend

Front End of my personal site justinwhall.com
JavaScript
1
star
17

redux-like-state-management-with-react-hooks

A simple Redux like state management but with React Hooks. 🎣
JavaScript
1
star