|
1 |
| -# Next.js WordPress Starter <!-- omit in toc --> |
| 1 | +# Next.js WordPress Starter |
2 | 2 |
|
3 |
| -WebDevStudios fork of the official Next.js WordPress [example](https://github.com/vercel/next.js/tree/canary/examples/cms-wordpress). Used as a starter for headless WordPress projects. |
4 |
| - |
5 |
| -**This project is still in active development. Use at your own risk.** |
6 |
| - |
7 |
| -https://nextjs-wordpress-starter-staging.vercel.app/ |
| 3 | +Our starter for headless WordPress projects. View the [demo](https://nextjs-wordpress-starter.vercel.app/) and read the [wiki](https://github.com/WebDevStudios/nextjs-wordpress-starter/wiki) to learn more. |
8 | 4 |
|
9 | 5 | <a href="https://webdevstudios.com/contact/"><img src="https://webdevstudios.com/wp-content/uploads/2018/04/wds-github-banner.png" alt="WebDevStudios. Your Success is Our Mission."></a>
|
10 | 6 |
|
11 |
| -## 🗂 Table of Contents <!-- omit in toc --> |
12 |
| - |
13 |
| -- [🎓 Overview](#-overview) |
14 |
| - - [Why?](#why) |
15 |
| - - [How's this all work?](#hows-this-all-work) |
16 |
| - - [3rd Party Services](#3rd-party-services) |
17 |
| - - [Algolia](#algolia) |
18 |
| - - [Chromatic](#chromatic) |
19 |
| - - [Vercel](#vercel) |
20 |
| - - [WP Engine](#wp-engine) |
21 |
| -- [🚀 Frontend Setup (Next.js)](#-frontend-setup-nextjs) |
22 |
| - - [Dependencies](#dependencies) |
23 |
| - - [Install](#install) |
24 |
| -- [🔧 Backend Setup (WordPress)](#-backend-setup-wordpress) |
25 |
| - - [Dependencies](#dependencies-1) |
26 |
| - - [Install](#install-1) |
27 |
| - - [Enable Previews](#enable-previews) |
28 |
| -- [💻 WebDevStudios Specific Info](#-webdevstudios-specific-info) |
29 |
| - - [WordPress Github](#wordpress-github) |
30 |
| - - [WP Engine](#wp-engine-1) |
31 |
| - - [Chromatic](#chromatic-1) |
32 |
| - - [1Password](#1password) |
33 |
| - - [Migrate DB Pro](#migrate-db-pro) |
34 |
| - - [Algolia](#algolia-1) |
35 |
| - - [Copy WP Engine Environments](#copy-wp-engine-environments) |
36 |
| -- [:octocat: Development and Contributing](#octocat-development-and-contributing) |
37 |
| - |
38 | 7 | ---
|
39 | 8 |
|
40 |
| -## 🎓 Overview |
41 |
| - |
42 |
| -### Why? |
43 |
| - |
44 |
| -Querying a REST-API or GraphQL endpoint and looping over blog posts is where many _"how to build a headless WordPress website"_ tutorials stop. You'd be hard pressed to find anything about supporting advanced features and plugins because **_headless WordPress is hard._** |
45 |
| - |
46 |
| -At WebDevStudios we believe that WordPress is so much more than a blog-- and our clients require support for things like: SEO, forms, previews, search, comments, authentication, custom post types, custom fields, etc... |
47 |
| - |
48 |
| -With this starter, we've figured out the "hard stuff" and placed the sum of our knowledge into something both the community and our future projects could use as a jumping off point. |
49 |
| - |
50 |
| -### How's this all work? |
51 |
| - |
52 |
| -The frontend (Next.js) talks to the backend (WordPress) via GraphQL. |
53 |
| - |
54 |
| -<details> |
55 |
| -<img src="https://dl.dropbox.com/s/9wsal7szatfwt6g/nextjs-wordpress-starter-frontend-backend-graphic.png?dl=0" alt="A graphic showing the relationship between environments"> |
56 |
| -</details> |
57 |
| - |
58 |
| -### 3rd Party Services |
59 |
| - |
60 |
| -This starter uses a few 3rd party services. |
61 |
| - |
62 |
| -<details> |
| 9 | +## Supported WordPress Features |
63 | 10 |
|
64 |
| -- [Algolia](https://www.algolia.com/) |
65 |
| -- [Chromatic](https://www.chromatic.com/) |
66 |
| -- [Vercel](https://vercel.com/) |
67 |
| -- [WP Engine](https://wpengine.com) |
68 |
| - |
69 |
| -#### Algolia |
70 |
| - |
71 |
| -We use [WP Search with Algolia](https://wordpress.org/plugins/wp-search-with-algolia/) to push content indicies from WordPress to Algolia. You will need to set up a (free) account and place your API credentials in the frontend `.env` file _and_ in the WordPress plugin settings. |
72 |
| - |
73 |
| -#### Chromatic |
74 |
| - |
75 |
| -Chromatic automates gathering UI feedback, visual testing, and documentation, so developers can iterate faster with less manual work. You will need to update both [`package.json`](https://github.com/WebDevStudios/nextjs-wordpress-starter/blob/staging/package.json#L34) and [`chromatic.yml`](https://github.com/WebDevStudios/nextjs-wordpress-starter/blob/staging/.github/workflows/chromatic.yml) with your Chromatic API key in order to automate builds. |
76 |
| - |
77 |
| -#### Vercel |
78 |
| - |
79 |
| -Vercel is the company behind Next.js and offers a platform _[that was built for deploying](https://vercel.com/solutions/nextjs)_ Next.js apps. |
80 |
| - |
81 |
| -Vercel has a generous free tier and offers support for both serverless functions (required if using incremental static regeneration) and [`next/image`](https://nextjs.org/docs/api-reference/next/image). Something neither Netlify nor Cloudflare support. |
82 |
| - |
83 |
| -#### WP Engine |
84 |
| - |
85 |
| -We're a partner with WP Engine and love their managed WordPress hosting options. That said, while hosting your headless WordPress install on WP Engine is recommended, it is not required. |
86 |
| - |
87 |
| -</details> |
| 11 | +- Advanced Custom Fields Pro |
| 12 | +- Algolia Search |
| 13 | +- Content Blocks |
| 14 | + - ACF Blocks |
| 15 | + - Gutenberg |
| 16 | + - Lazy Blocks |
| 17 | +- Custom 404 page |
| 18 | +- Custom Post Types |
| 19 | +- Gravity Forms |
| 20 | +- Previews |
| 21 | +- WordPress SEO (Yoast) |
88 | 22 |
|
89 | 23 | ---
|
90 | 24 |
|
91 |
| -## 🚀 Frontend Setup (Next.js) |
92 |
| - |
93 |
| -The following steps will stand up a local install of Next.js. |
94 |
| - |
95 |
| -### Dependencies |
96 |
| - |
97 |
| -Before you get started, make sure you have the following dependencies installed on your computer: |
98 |
| - |
99 |
| -- [Node 12](https://nodejs.org/en/) |
100 |
| -- [Yarn](https://yarnpkg.com/) |
101 |
| -- [Vercel CLI](https://vercel.com/download) |
102 |
| - |
103 |
| -### Install |
104 |
| - |
105 |
| -**Step 1: Clone the repo** |
106 |
| - |
107 |
| -```bash |
108 |
| -git clone [email protected]:WebDevStudios/nextjs-wordpress-starter.git |
109 |
| -``` |
110 |
| - |
111 |
| -**Step 2: Change directories** |
112 |
| - |
113 |
| -```bash |
114 |
| -cd nextjs-wordpress-starter |
115 |
| -``` |
116 |
| - |
117 |
| -**Step 3: Install dependencies** |
118 |
| - |
119 |
| -```bash |
120 |
| -yarn |
121 |
| -``` |
122 |
| - |
123 |
| -**Step 4: Setup ENV Variables** |
124 |
| - |
125 |
| -ENV variables are like constants in `wp-config.php`. They're required in order for authentication and 3rd party services to work. |
126 |
| - |
127 |
| -Copy the [sample ENV file](https://github.com/WebDevStudios/nextjs-wordpress-starter/blob/staging/.env.sample), then modify it to match your credentials: |
128 |
| - |
129 |
| -```bash |
130 |
| -cp .env.sample .env |
131 |
| -``` |
132 |
| - |
133 |
| ---OR-- |
134 |
| - |
135 |
| -[Link the project with Vercel](https://vercel.com/docs/cli#commands/overview/project-linking), then pull down the ENV variables: |
136 |
| - |
137 |
| -<details> |
138 |
| - |
139 |
| -The preferred workflow is to add ENV variables to Vercel first, then pull them down. |
140 |
| - |
141 |
| -**Step 1: Add ENV vars to Vercel** |
142 |
| - |
143 |
| -Go to: |
144 |
| - |
145 |
| -```text |
146 |
| -Your Project --> Settings --> Environment Variables |
147 |
| -``` |
148 |
| - |
149 |
| - |
150 |
| - |
151 |
| -**Step 2: Install the [Vercel CLI](https://vercel.com/download)** |
152 |
| - |
153 |
| -```bash |
154 |
| -npm i -g vercel |
155 |
| -``` |
156 |
| - |
157 |
| -**Step 3: Initialize Vercel** |
158 |
| - |
159 |
| -Answer the questions in the command line when prompted. |
160 |
| - |
161 |
| -```bash |
162 |
| -vercel init |
163 |
| -``` |
164 |
| - |
165 |
| -**Step 4: Pull down the ENV variables** |
166 |
| - |
167 |
| -```bash |
168 |
| -vercel env pull |
169 |
| -``` |
170 |
| - |
171 |
| -Now Next.js has what it needs to talk to 3rd party services. |
172 |
| - |
173 |
| -</details> |
174 |
| - |
175 |
| ---- |
176 |
| - |
177 |
| -## 🔧 Backend Setup (WordPress) |
178 |
| - |
179 |
| -The following steps will stand up a local install of WordPress. |
180 |
| - |
181 |
| -### Dependencies |
182 |
| - |
183 |
| -Before you get started, make sure you have the following dependency installed on your computer: |
184 |
| - |
185 |
| -- [Local WP](https://localwp.com/) |
186 |
| - |
187 |
| -### Install |
188 |
| - |
189 |
| -**Step 1: Download the Local WP export** |
190 |
| - |
191 |
| -- [nextjs-wp-01.29.2021.zip (162MB)](https://drive.google.com/file/d/1iTVxyTS6ezy6RUhba9CbAjZL1x3iZyv7/view?usp=sharing) |
192 |
| - |
193 |
| -**Step 2: Import the .zip** |
194 |
| - |
195 |
| -- https://localwp.com/help-docs/getting-started/how-to-import-a-wordpress-site-into-local/ |
196 |
| - |
197 |
| -**Step 3: Configure `wp-config.php`** |
198 |
| - |
199 |
| -The follow constants needs to be in `wp-config.php`: |
200 |
| - |
201 |
| -```php |
202 |
| -define('HEADLESS_FRONTEND_URL', 'http://localhost:3000/'); |
203 |
| -define('PREVIEW_SECRET_TOKEN', 'ANY_RANDOM_STRING'); |
204 |
| -``` |
205 |
| - |
206 |
| -**Step 4: Start the `nextjs-wp` site** |
207 |
| - |
208 |
| -### Enable Previews |
209 |
| - |
210 |
| -To enable previews, you'll need both a `PREVIEW_SECRET_TOKEN` constant in `wp-config.php` and `WORDPRESS_PREVIEW_SECRET` ENV variable in `.env`. |
211 |
| - |
212 |
| -The token can be any random string as long as they match. |
213 |
| - |
214 |
| ---- |
215 |
| - |
216 |
| -## 💻 WebDevStudios Specific Info |
217 |
| - |
218 |
| -The following information pertains to internal tools and workflows at WebDevStudios. |
219 |
| - |
220 |
| -<details> |
221 |
| - |
222 |
| -### WordPress Github |
223 |
| - |
224 |
| -There is a Github repo for the backend. This repo manages plugins and the headless theme. Future projects should probably mimic this setup: |
225 |
| - |
226 |
| -https://github.com/WebDevStudios/nextjs-starter-wordpress |
227 |
| - |
228 |
| -**Note: There is no frontend for WordPress** - But it is running a headless theme which houses `/acf-json` and other headless-related functions. |
229 |
| - |
230 |
| -### WP Engine |
231 |
| - |
232 |
| -There are 3 WordPress environments on WP Engine: |
233 |
| - |
234 |
| -- [Develop](https://nextjsdevstart.wpengine.com/wp-admin/) |
235 |
| -- [Staging](https://nextjsstgstart.wpengine.com/wp-admin/) |
236 |
| -- [Production](https://nextjs.wpengine.com/wp-admin) |
237 |
| - |
238 |
| -Use the orange "WebDevStudios Login" button to log in. |
239 |
| - |
240 |
| -### Chromatic |
241 |
| - |
242 |
| -This project supports UI review via Chromatic, which is triggered via Github Actions. |
243 |
| - |
244 |
| -View this project's [Chromatic](https://chromatic.com/library?appId=5fe0becf19ad53002147b034&branch=staging) by logging in with your WDS Github account. |
245 |
| - |
246 |
| -### 1Password |
247 |
| - |
248 |
| -All of the credentials are in the following vault: |
249 |
| - |
250 |
| -```text |
251 |
| -1Password --> Next.js Starter |
252 |
| -``` |
253 |
| - |
254 |
| -### Migrate DB Pro |
255 |
| - |
256 |
| -You can use Migrate DB Pro to pull databases and files. Please see 1password for credentials |
257 |
| - |
258 |
| -### Algolia |
259 |
| - |
260 |
| -The login and API credentials are in password. |
261 |
| - |
262 |
| -### Copy WP Engine Environments |
263 |
| - |
264 |
| -WP Engine supports [copying environments](https://wpengine.com/support/copy-site/). This should be done at the end of two week sprints (or as needed). |
265 |
| - |
266 |
| -**The following steps will copy Develop to Staging:** |
267 |
| - |
268 |
| -1. Log into the WP Engine [User Portal](https://my.wpengine.com/sites) |
269 |
| -2. Click on [Nextjsstgstart](https://my.wpengine.com/installs/nextjsstgstart) |
270 |
| -3. In the top right corner, click the "Copy environment" button |
271 |
| -4. Select the options: |
272 |
| -  |
273 |
| -5. Click "Preview copy" and a modal will appear to let you verify the options |
274 |
| -6. Click "Copy environment" |
275 |
| - |
276 |
| -</details> |
277 |
| - |
278 |
| ---- |
279 |
| - |
280 |
| -## :octocat: Development and Contributing |
281 |
| - |
282 |
| -At WebDevStudios we are committed to open-source technologies and welcome feedback, [discussions](https://github.com/WebDevStudios/nextjs-wordpress-starter/discussions), and contributions from the community. |
| 25 | +## :octocat: Contributing |
283 | 26 |
|
284 |
| -Please see [CONTRIBUTING.md](https://github.com/WebDevStudios/nextjs-wordpress-starter/blob/staging/.github/CONTRIBUTING.md) for more info on how to get started. |
| 27 | +WebDevStudios is committed to open-source technologies and welcomes feedback via [Github Discussions](https://github.com/WebDevStudios/nextjs-wordpress-starter/discussions). We're also accepting contributions from the community. Learn how to [contribute to this project](https://github.com/WebDevStudios/nextjs-wordpress-starter/blob/staging/.github/CONTRIBUTING.md). |
285 | 28 |
|
286 | 29 | Stay safe! 🍻
|
0 commit comments