Documentation
WP Template setup and usage
Requirements
Node.js 20+Yarn 1.22+WordPress 6.0+
Quick Start
# 1. Clone the repository
git clone https://github.com/your-repo/wp-template.git
cd wp-template
# 2. Install dependencies
yarn install
# 3. Set up environment variables
cp .env.example .env.local
# Edit .env.local and configure WordPress connection information
# 4. Start the development server
yarn dev:next-wp-templateEnvironment Variables
| Variable Name | Description |
|---|---|
| NEXT_PUBLIC_WORDPRESS_API_URL | WordPress REST API URL |
| NEXT_PUBLIC_WORDPRESS_HOST | WordPress hostname |
| WP_AUTH_TOKEN | WordPress application password |
| REVALIDATE_SECRET | Secret for ISR revalidation |
| WEBHOOK_SECRET | Secret for webhook authentication |
WordPress Setup
- Enable REST API
Verify that WordPress REST API is enabled by default
- Create Application Password
User Settings → Application Passwords → Create New
- CORS Configuration
Allow access from Next.js frontend
// Add to functions.php add_action('rest_api_init', function() { header('Access-Control-Allow-Origin: https://your-next-domain.com'); header('Access-Control-Allow-Methods: GET, POST, OPTIONS'); }); - Webhook Configuration
Configure to call Next.js Revalidate API when posts are updated
// Add to functions.php add_action('save_post', function($post_id) { $url = 'https://your-next-domain.com/api/revalidate'; wp_remote_post($url, [ 'body' => json_encode(['secret' => REVALIDATE_SECRET, 'slug' => get_post($post_id)->post_name]), 'headers' => ['Content-Type' => 'application/json'] ]); });