A modern, production-ready Next.js starter for headless WordPress. Build blazing-fast websites with WordPress as your CMS and Next.js as your frontend.
- Next.js 15 - App Router, React Server Components, streaming
- Gutenberg Block Rendering - Custom block components with HTML fallback
- Full Blog System - Archive, single posts, categories, tags, pagination
- Search - Full-text search across all content types with filters
- Form Support - WPForms integration with proxy submission handling
- Preview Mode - Live preview of draft content from WordPress
- ISR - Incremental Static Regeneration with on-demand revalidation
- Dark Mode - Tailwind CSS with dark theme out of the box
- TypeScript - Full type safety throughout
- Node.js 18+
- pnpm (recommended) or npm
- WordPress with WPGraphQL plugin
- FlatWP Plugin installed on WordPress
git clone https://github.com/flatwp/flatwp-starter.git
cd flatwp-starterpnpm install
# or
npm installcp .env.example .env.localEdit .env.local with your WordPress details:
NEXT_PUBLIC_WORDPRESS_API_URL=https://your-wordpress-site.com/graphql
NEXT_PUBLIC_WORDPRESS_DOMAIN=your-wordpress-site.com
FLATWP_SECRET=your-secret-key-hereGenerate a secret with:
openssl rand -base64 32
pnpm dev
# or
npm run devVisit http://localhost:3000
- WPGraphQL - Exposes WordPress data via GraphQL
- FlatWP Plugin - Handles preview mode, revalidation, and block rendering
In WordPress admin, go to Settings > FlatWP and configure:
| Setting | Value |
|---|---|
| Frontend URL | Your Next.js URL (e.g., http://localhost:3000) |
| API Secret | Same value as FLATWP_SECRET in your .env.local |
| Redirect Frontend | Enable to route all traffic through Next.js |
flatwp-starter/
├── app/ # Next.js App Router
│ ├── api/ # API routes
│ │ ├── forms/ # Form submission handlers
│ │ ├── preview/ # Preview mode
│ │ ├── revalidate/ # ISR revalidation
│ │ └── search/ # Search API
│ ├── blog/ # Blog pages
│ ├── search/ # Search page
│ └── [...slug]/ # Dynamic page routes
├── components/
│ ├── blocks/ # Gutenberg block renderers
│ ├── blog/ # Blog components
│ ├── layout/ # Header, Footer
│ └── search/ # Search components
└── lib/
├── config/ # Site configuration
└── wordpress/ # GraphQL client & queries
All configuration is in lib/config/:
| File | Purpose |
|---|---|
site.config.ts |
Site name, SEO, branding |
navigation.config.ts |
Menu items and structure |
blog.config.ts |
Blog layout and features |
layout.config.ts |
Page widths, footer settings |
search.config.ts |
Search behavior |
forms.config.ts |
Form plugin settings |
// lib/config/site.config.ts
export const siteConfig = {
name: 'My Awesome Site',
description: 'Built with FlatWP',
// ...
};FlatWP uses a hybrid approach for Gutenberg blocks:
- Custom Components - React components for FlatWP blocks
- HTML Fallback - Server-rendered HTML for core WordPress blocks
- Create a component in
components/blocks/:
// components/blocks/MyBlock.tsx
export function MyBlock({ block }: { block: EditorBlock }) {
const { attributes } = block;
return <div>{attributes.content}</div>;
}- Register in
EditorBlockRenderer.tsx:
const BLOCK_COMPONENTS = {
'my-plugin/my-block': MyBlock,
// ...
};- Push to GitHub
- Import project in Vercel
- Add environment variables
- Deploy
Set these in your hosting platform:
NEXT_PUBLIC_WORDPRESS_API_URL=https://your-wp.com/graphql
NEXT_PUBLIC_WORDPRESS_DOMAIN=your-wp.com
NEXT_PUBLIC_SITE_URL=https://your-frontend.com
FLATWP_SECRET=your-production-secret
| Command | Description |
|---|---|
pnpm dev |
Start development server |
pnpm build |
Build for production |
pnpm start |
Start production server |
pnpm lint |
Run ESLint |
pnpm typecheck |
Run TypeScript check |
Clear the Next.js cache:
rm -rf .next && pnpm dev- Ensure WPForms is installed and configured in WordPress
- Check that the form has AJAX submission enabled
- Verify CORS headers are set in WordPress
- Verify
FLATWP_SECRETmatches between Next.js and WordPress - Check the Frontend URL is correct in FlatWP plugin settings
- Ensure the WordPress user is logged in
Contributions are welcome! Please read our contributing guidelines before submitting PRs.
MIT License - see LICENSE for details.