Skip to content
Projects

colbyfayock/next-wordpress-starter

View on GitHub

About

๐Ÿ“ Bring WordPress to the static world with Next.js

Web & App Development

How these counts are measured

Measured star growth

in 24h
0
in 7 days
+1
in 15 days
+1
in 1 month
-1

Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.

README.md

Original

Next.js WordPress Starter

All Contributors

Scaling WordPress with the power of Next.js and the static web!

โšก๏ธ Quick Start

Deploy to Netlify Deploy with Vercel

Requirements

yarn create next-app -e https://github.com/colbyfayock/next-wordpress-starter
# or
npx create-next-app -e https://github.com/colbyfayock/next-wordpress-starter

Add an .env.local file to the root with the following:

WORDPRESS_GRAPHQL_ENDPOINT="http://wordpressite.com/graphql"

In some cases, the above may not work. Change it as follows:

WORDPRESS_GRAPHQL_ENDPOINT="http://yourhost.com/index.php?graphql"

๐Ÿš€ Getting Started

What is this and what does it include?

The goal of this project is to take WordPress as a headless CMS and use Next.js to create a static experience without any 3rd party services that can be deployed anywhere.

The hope is to build out as many features as we can to support what's typically expected from an out of the box theme on WordPress. Currently, those features include:

Additionally, the theme is expected to be SEO friendly and performant out of the box, including:

  • Unique page titles
  • Unique descriptions
  • Open Graph tags

You can also optionally enable Yoast SEO plugin support to supercharge your SEO! (See below)

Check out the Issues for what's on deck!

Want something a little more basic? Check out my other starter with an MVP setup to get up and running with WPGraphQL in WordPress: https://github.com/colbyfayock/next-wpgraphql-basic-starter

Requirements

Environment

This project makes use of WPGraphQL to query WordPress with GraphQL. In order to make that request to the appropriate endpoint, we need to set a environment variable to let Next.js know where to request the site information from.

Create a new file locally called .env.local and add the following:

WORDPRESS_GRAPHQL_ENDPOINT="[WPGraphQL Endpoint]"

Replace the contents of the variable with your WPGraphQL endpoint. By default, it should resemble [Your Host]/graphql.

Note: environment variables can optionally be statically configured in next.config.js

All Environment Variables

Name Required Default Description
WORDPRESS_GRAPHQL_ENDPOINT Yes - WordPress WPGraphQL endpoint (ex: host.com/graphl)
WORDPRESS_MENU_LOCATION_NAVIGATION No PRIMARY Configures header navigation Menu Location
WORDPRESS_PLUGIN_SEO No false Enables SEO plugin support (true, false)

Please note some themes do not have PRIMARY menu location.

Development

This project uses Next.js 16 with the Pages Router and React 18. The build and development scripts select Webpack so the custom search-index, sitemap, and RSS plugins continue to run.

Use Node.js 26 (nvm use reads .nvmrc) and install dependencies with pnpm install --frozen-lockfile. Use pnpm 7.33.7 to preserve the checked-in lockfile format.

To start the project locally, run:

yarn dev
# or
npm run dev

The project should now be available at http://localhost:3000!

Styling

Component and page styles use CSS Modules (*.module.css). Shared colors, fonts, border radii, and the navigation progress-bar color are CSS custom properties in src/styles/tokens.css.

To customize the theme, update those properties or override them on a component. Use var(--color-primary) and the other shared properties in stylesheets. Global styles live in src/styles/globals.css, and WordPress content styles live in src/styles/wordpress.css.

Linting and formatting

This project uses Oxlint for linting and Oxfmt for formatting. Their settings live in .oxlintrc.json and .oxfmtrc.json.

pnpm lint          # check for problems
pnpm lint:fix      # apply safe fixes
pnpm format        # format files
pnpm format:check  # check formatting without writing (also run in CI)

To format on save in Visual Studio Code, install the Oxc extension and add a .vscode/settings.json file:

{
  "editor.defaultFormatter": "oxc.oxc-vscode",
  "editor.formatOnSave": true
}

See the Oxc docs for other editors and linter integration.

Deployment

Netlify

There are two options as to how you can deploy this project to Netlify:

Essential Next.js Plugin should be provided as an option when you're first importing a project based on this starter. If it's not, you can install this plugin using the Netlify Plugins directory. This will allow the project to take full advantage of all native Next.js features that Netlify supports with this plugin. This project uses @netlify/plugin-nextjs v5, which is required for Next.js 16.

Exporting the project lets Next.js compile the project into static assets including HTML files. This allows you to deploy the project as a static site directly to Netlify just like any other site. next export was removed in Next.js 14, so run pnpm export (which runs NEXT_EXPORT=true next build --webpack) and publish the out directory. The export only includes pages that are pre-rendered at build time, as on-demand fallback pages (ex: author pages) aren't supported by static exports; those routes are only available with the plugin deployment.

Regardless of which option you choose, you can configure your environment variables either when creating your new site or by navigating to Site Settings > Build & Deploy > Environment and triggering a new deploy once added.

Deploy to Netlify

Vercel

The engines.node setting in package.json pins builds and functions to Node.js 26.x, overriding the Node.js version selected in Vercel Project Settings.

Given Next.js is a Vercel-supported project, you can simply import the project as a new site and configure your environment variables by either adding them during import or by navigating to Settings > Environment Variables and triggering a new build once added.

Deploy with Vercel

๐Ÿ›  Configuring Your Project

package.json

In order to avoid an additional configuration file, we take advantage of some built-in properties of package.json to configure parts of the website.

Name Required Description
homepage Yes Homepage or hostname used to construct full URLs (ex Open Graph)
  • homepage: Setting the homepage property will update instances where the full URL is required such as Open Graph tags

WordPress

This project aims to take advantage of as many built-in WordPress features by default like a typical WordPress theme. Those include:

Name Usage
Site Language lang attribute on the <html> tag
Site Title Homepage header, page metadata
Tagline Homepage subtitle

There is some specific WordPress configuration required to allow for the best use of this starter.

Images

This Starter doesn't currently provide any mechanisms for dealing with image content from WordPress. The images are linked to "as is", meaning if the image is uploaded via the WordPress interface, the image will be served from WordPress.

To serve the images statically, you have a few options.

Jetpack

By enabling the Image Accelerator from Jetpack, your images will automatically be served statically and cached via the wp.com CDN. This feature comes free with the basic installation of Jetpack, requiring only that you connect the WordPress site to the Jetpack service.

Jetpack CDN

๐Ÿ”Œ Plugins

Yoast SEO

The Yoast SEO plugin is partially supported including most major features like metadata and open graph customization.

Requirements

  • Yoast SEO plugin
  • Add WPGraphQL SEO plugin

To enable the plugin, configure WORDPRESS_PLUGIN_SEO to be true either as an environment variable or within next.config.js.

๐Ÿฅพ Bootstrapped with Next.js WordPress Starter

Examples of websites that started off with Next.js WordPress Starter

๐Ÿ’ Sponsors

WordPress hosting for the public-facing project provided by WP Engine.

WP Engine Logo

โœจ Contributors

Thanks goes to these wonderful people (emoji key):

Colby Fayock
Colby Fayock

๐Ÿ’ป ๐Ÿ“–
Kevin Cunningham
Kevin Cunningham

๐Ÿ’ป
Guillermo Angulo
Guillermo Angulo

๐Ÿ’ป
Hein Snyman
Hein Snyman

๐Ÿ’ป
Grische
Grische

๐Ÿ”ง
Jatin Rathee
Jatin Rathee

๐Ÿ’ป
Dave
Dave

๐Ÿ’ป
Brad Garropy
Brad Garropy

๐Ÿ’ป
Fรกbio Sales
Fรกbio Sales

๐Ÿ’ป
Leonardo Losoviz
Leonardo Losoviz

๐Ÿ’ป
Avneesh Agarwal
Avneesh Agarwal

๐Ÿ’ป
Phattarapol L.
Phattarapol L.

๐Ÿ’ป
Peter Cruckshank
Peter Cruckshank

๐Ÿ’ป
Shane O'Grady
Shane O'Grady

๐Ÿ’ป
Nick Gaswirth
Nick Gaswirth

๐Ÿ’ป
alexandruvisan19
alexandruvisan19

๐Ÿ’ป
Ritik Chourasiya
Ritik Chourasiya

๐Ÿ”ง
Rick Knowlton
Rick Knowlton

๐Ÿ’ป
Jedidiah Amaraegbu
Jedidiah Amaraegbu

๐Ÿ“–

This project follows the all-contributors specification. Contributions of any kind welcome!

Explore related projects

Loadingโ€ฆ