• Stars
    star
    635
  • Rank 70,829 (Top 2 %)
  • Language
    JavaScript
  • License
    GNU General Publi...
  • Created about 4 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

🔥 Nextjs Headless WordPress

🎨 Next.js Headless WordPress

Project Status: Active. Stars Forks Contributors Follow

  • Headless WordPress, using Decoupled Architecture in Next.js
  • Backend in WordPress using WPGraphQL
  • Front end in React.

Features

  1. Home Page, Blog Page, Post Page
  2. Post Preview
  3. Post Pagination.
  4. Load More Posts.
  5. SEO Component fetching data Yoast SEO with schema
  6. Cypress for tests, Eslint for linting.
  7. Apollo Client with GraphQL
  8. Api endpoints.
  9. Header and Footer in Next.js fetching from WordPress Menu items.
  10. WordPress Widgets displayed on Next.js frontend.
  11. Site title, tagline, copyright text, sourced from WordPress.
  12. Next.js Image component, that has image optimization at request time.
  13. Authentication with JWT and Http Only Cookie implementation.
  14. Login feature for WP Post Preview in Next.js
  15. Incremental Static (Re)generation and automatic creation of New Static post pages without having to re-build next.js the application.
  16. Gutenberg styles support

Tutorial Course

Code for the tutorial is in the Tutorial Branch

Live Demo Link

https://nextjs-headless-wordpress-demo.vercel.app/

Setup

First clone/fork the repo and cd into it.

git clone https://github.com/imranhsayed/nextjs-headless-wordpress.git
cd nextjs-headless-wordpress

It's very simple to setup the project with just one command and this ./nxtwp configure

One command project setup

The below command is going to set up the project in the interactive mode. It creates an .env file for front-end next.js project and setsup up frontend and/or backend. Run this from the root of the project.

./nxtwp configure

It's going to ask you a few of questions.

Q1. Do you already have a WordPress setup that you want to continue with? [y/n]:

Answer

y: If you would like to use this project's WordPress Docker setup ( In which case make sure to install and active all plugins from [backend/plugins-collection]) n: If you want to use your own WordPress setup.

Q2. ✍️  What is your WP backend URL? (defaults to http://localhost:8020): 

Leave it blank if you would like to use this project's WordPress Docker setup, else enter your own WordPress site URL.

✍️  What is your frontend next js URL? (defaults to http://localhost:3000):

Leave this blank for development, as it will be the same as default for next.js

✍️  What is your Disqus comments shortname? (leave blank if you are not using): 

Leave this blank if you are not going to use the Disqus comments, else enter your Disqus comments shortname.

This is going to automatically:

  • Creates the .env file in the frontend directory.
  • Setup WordPress backend with all the plugins via composer (if you chose y for the first question)
  • Install npm packages for next.js frontend and start development server.

WordPress Backend will be available on http://localhost:8020 Next.js Backend will be available on port http://localhost:3000

  • Make sure to activate all plugins that it has installed via composer.
  • Update block registry by going to WordPress Dashboard > GraphQL Gutenberg.
  • Update the permalink by going to Settings > Permalinks > Post name > Save
  • Copy the backend/wordpress/.htaccess file content into your WordPress .htaccess
  • For more information checkout the project Wiki

That's it!

During development

Useful commands: To be run from the root of the project.

./nxtwp configure       # Sets up backend and frontend and creates an .env file
./nxtwp start-all       # Creates and starts docker environment for WP and runs Next JS server
./nxtwp start-backend   # Creates and starts docker environment
./nxtwp start-frontend  # Installs all packages and Runs Next JS server
./nxtwp stop            # Stops the WordPress docker containers

Debugging

  1. If you get 404 on frontend for graphql request, check to see that the .htaccess file in wordpress directory has the rules
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
  1. If front-end is throwing some other error.
  • Check if all the required WordPress plugins form backend/plugins-collection are active.
  • Ensure you have updated the block registry from WordPress backend > GraphQL Gutenberg
  • Ensure that .env file has correct env variables and their values in frontend/.env

References for Docker Images.

  1. phpMyAdmin

More Repositories

1

woo-next

🚀 React WooCommerce theme, built with Next JS, Webpack, Babel, Node, Express, using GraphQL and Apollo Client
JavaScript
880
star
2

aquila

🎨 An Advanced WordPress theme
PHP
737
star
3

gatsby-woocommerce-themes

⚡ A Gatsby Theme for WooCommerce E-commerce site Gatsby WooCommerce WordPress
JavaScript
597
star
4

gatsby-wordpress-themes

🎨 Gatsby WordPress Theme
JavaScript
346
star
5

react-with-wordpress

🔥 Example of react application to access WordPress REST API
JavaScript
230
star
6

nextjs-woocommerce-restapi

A React WooCommerce Project Example With REST API
JavaScript
199
star
7

headless-cms

❤️ A WordPress plugin that adds features to use WordPress as a headless CMS with any front-end environment using REST API
PHP
180
star
8

google-maps-in-react

📌 Google Maps in React: Autocomplete Location Search | Draggable Marker | Marker Infobox
JavaScript
168
star
9

react-workshop

⚒️ 🚧 This is a workshop for learning how to build React Applications
162
star
10

file-uploads-aws-react-node

📂 A react node and express js project to upload files on amazon web services ( AWS )
JavaScript
98
star
11

advanced-woocommerce-theme

🛍️ Advanced WooCommerce Theme
PHP
73
star
12

react-pwa-workbox-example

react-pwa-workbox-example
JavaScript
69
star
13

react-wordpress-theme

🎨 A React theme for WordPress, using Decoupled Architecture. Front end in React. Backend in WordPress.
CSS
68
star
14

frontity-contact-form-7

🔥 Contact Form 7 extension for Frontity theme.
JavaScript
66
star
15

aquila-features

Advanced WordPress Plugin Development
JavaScript
64
star
16

next-js-app

🌐 Next JS Application Demo
JavaScript
52
star
17

frontity-twentynineteen

🎨 A Frontity Twentynineteen theme Project
CSS
51
star
18

laravel-charts

📊 Create a chart in Laravel using Chart.js and AJAX
PHP
37
star
19

tailwind-wordpress-plugin-example

An example WordPress plugin for using Tailwind css in Gutenberg editor with webpack and sass
JavaScript
37
star
20

woocommerce-custom-pages

✅ Custom template and Pages for Woocommerce that can be used to customize your Woocommerce Product, Categories, Cart, Checkout and Myaccount Pages
PHP
35
star
21

rest-api-endpoints

🌾 WordPress REST API endpoints
PHP
34
star
22

google-maps-javascript-api

🔎Create Google maps for your site with google maps javascript api, address field, marker and info window
JavaScript
29
star
23

nextjs-wordpress-theme

🎨 A Next.js WordPress theme that uses React in the front-end and WordPress in the backend - decoupled
JavaScript
28
star
24

wordpress-docker-example

A WordPress setup with Docker, Composer, mysql and phpmyadmin
23
star
25

headless-wp-starter

🌀 A starter demo for WordPress Headless CMS
JavaScript
22
star
26

electra

Block Based Theme - Full Site Editing Tutorial
HTML
22
star
27

gutenberg-workshop

⚒️ A Gutenberg Workshop 🅱️
PHP
22
star
28

custom-blocks

📦 Custom Gutenberg Blocks
PHP
21
star
29

graphql-react-app

📊 A demo app for using GraphQl with React and Spacex API
JavaScript
21
star
30

graphql-workshop

⚒ 🚧 A GraphQL workshop to learn GraphQL implementations
JavaScript
20
star
31

acf-block-example

📦 ACF Blocks Example plugin
PHP
19
star
32

react-node-boilerplate

A React Js and Node Js boilerplate for building a new project. It uses create-react-app
JavaScript
19
star
33

wordpress-contributors

👥 This plugin allows you to add more than one author for the post in the Add New and Edit Post section of WordPress dashboard.
PHP
18
star
34

mern-boilerplate

A boilerplate for MERN APP ( Mongodb, Express, React, Node ) with Login, Registration with Facebook, Google and Recaptcha. Pre setup of mongodb
JavaScript
17
star
35

react-woocommerce-theme

🏬 A React WooCommerce Store Theme, built with WooCommerce REST API, Webpack, Babel, Node and Express
JavaScript
16
star
36

pwa-concepts

👷 A demo App PWA Concepts
HTML
16
star
37

more-menu-react

📇 A demo for display extra menu items dynamically in More menu, in React
JavaScript
15
star
38

react-hooks

⚓ A demo app for React Hooks
JavaScript
14
star
39

gatsby-with-wordpress-workshop

A Gatsby with WordPress workshop
JavaScript
14
star
40

javascript-workshop

🔥 JavaScript Beginner to Advanced Workshop
JavaScript
13
star
41

react-app-boilerplate

🔥 react-app-boilerplate
SCSS
13
star
42

javascript-concepts

🎓 A demo app for JavaScript Concepts
JavaScript
12
star
43

acf-guten-blocks

🔌 This plugin creates Gutenberg blocks using ACF
PHP
12
star
44

react-app

📦 A demo to set up React App with create-react-app, webpack and babel
JavaScript
11
star
45

ssr-react-app

⚡ A server-side-rendering-react-app demo
JavaScript
11
star
46

gutenberg-blocks-starter

A starter plugin to develop Gutenberg blocks.
JavaScript
11
star
47

remove-linkedin-connection

👤 Remove a LinkedIn Connection with a Single Click
JavaScript
10
star
48

gatsby-wp-themes

Gatsby WordPress Theme
JavaScript
10
star
49

nextjs-example

Nextjs Example
JavaScript
9
star
50

admin-menu-builder

A plugin that creates a menu in WordPress backend dashboard
PHP
9
star
51

imranhsayed

Bio
9
star
52

webpack-app

📦 A demo app for webpack app
JavaScript
9
star
53

my-gatsby-project

My Gatsby Test Project
JavaScript
9
star
54

redux-workshop

⚒ A Redux Workshop 🏂
9
star
55

react-beginners-course

react-beginners-course
JavaScript
8
star
56

gatsby-workshop

🛠️ A Gatsby Workshop
CSS
8
star
57

codeytek-blocks

Custom Gutenberg blocks for codeytek
JavaScript
8
star
58

instamojo-integration-nodejs

Instamojo Payment Gateway Integration Snippet using Node Js , React, Express and Mongo db
JavaScript
8
star
59

create-react-app-pwa-new

Create React App PWA
JavaScript
7
star
60

frontity-contact-form-7-test

📝 Frontity Contact Form Seven Feature
JavaScript
7
star
61

lazy-load

🌈 A WordPress theme to demonstrate lazy load feature
PHP
7
star
62

my-storybook

A demo project for storybook using create-react-app
JavaScript
7
star
63

ihs-forms

WordPress Forms with attachments
PHP
7
star
64

starter-block

Starter Block Plugin with wp-scripts package
JavaScript
7
star
65

react-mmenu

🎢 React mmenu
JavaScript
7
star
66

gatsby-app

A demo React application using gatsby
CSS
7
star
67

autoloaders-with-composer

⌛ Demo for autoloading with Composer
PHP
6
star
68

react-app-webpack

A demo project for react with webpack
JavaScript
6
star
69

redux-example

🌀 A redux example
JavaScript
6
star
70

CSS-Tricks

Useful links for CSS Tricks
6
star
71

cg-blocks

A custom gutenberg contact card block
JavaScript
6
star
72

ihs-geo-location

This plugin detects your location and makes certain classes available to you which you can apply to the div elements or use shortcodes in your theme to display the user's current locality, city, state, country and address.
PHP
6
star
73

contact-form-7-endpoints

🔥 This plugin provides you different endpoints for Contact Form 7 registration using WordPress REST API
PHP
6
star
74

wordpress-docker-wp-cli

An example of WordPress with Docker and WP-CLI setup
Shell
5
star
75

todo

🔥 A React Native App
Objective-C
5
star
76

jest-test-app

Test Application using JEST
HTML
5
star
77

taxonomies-wp-content

wp-content folder containing plugin and custom templates for custom post type custom taxonomy and custom product page examples
PHP
5
star
78

gatsby-experimental

👨‍🔬 Gastby WordPress site
JavaScript
5
star
79

tailwind-example

tailwind-example
JavaScript
5
star
80

shiprocket-pincode-check-woocommerce

The plugin checks if the woocommerce product can be delivered to your location using pincode. It uses Shiprocket Api to achieve this.
PHP
5
star
81

jest-for-react

A demo project for writing test for react using jest
JavaScript
4
star
82

todolist

A laravel Project for todolist
PHP
4
star
83

portfolio-app

A react application
JavaScript
4
star
84

babel-app

A repo for babel demo
JavaScript
4
star
85

laravel-auth

Custom Login and Registration database name in the .env file is laravel_auth, id root and password: empty
PHP
4
star
86

nextjs

Next js app
JavaScript
4
star
87

pop-up-window

Create Modal Box/ Pop up window using JavaScript
CSS
4
star
88

add-post-script-plugin

A custom WordPress plugin that adds custom fields below every Post/Page to allow user to add post/page specific styles and scripts
PHP
4
star
89

Publish-plugin-on-WordPress

🔌 How to Publish Your Plugin on WordPress and Update and tag a version
HTML
4
star
90

nextjs-wp-assets

A set of assets for nextjs-wp project
CSS
4
star
91

basicwebsite

A basic laravel website with contact form
PHP
4
star
92

laravel-blogs

📄 Blog Posting CRUD functionality in Laravel with Bootstrap
PHP
4
star
93

node-playground

🌐 A demo app for node
JavaScript
4
star
94

express-app

⚡ A demo app for Express
JavaScript
4
star
95

item-laravel-api

A laravel Project to perform CRUD request with REST API via ajax request. Front end will be available in itemmanager directory and itemapi is a laravel dir
PHP
4
star
96

gutenberg-block-scaffold-examples

An example of Gutenberg Block Scaffoldings
JavaScript
3
star
97

wp-plugin-webpack-boilerplate

Boilerplate - WordPress Plugin With Webpack setup
JavaScript
3
star
98

programming-in-java

Example programs in Java
Java
3
star
99

add-script-plugin

A Custom WordPress plugin to add styles and scripts from the backend dashboard
PHP
3
star
100

python-programming

Example projects for Python Programming
Python
3
star