Skip to main content

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-template

Environment Variables

Variable NameDescription
NEXT_PUBLIC_WORDPRESS_API_URLWordPress REST API URL
NEXT_PUBLIC_WORDPRESS_HOSTWordPress hostname
WP_AUTH_TOKENWordPress application password
REVALIDATE_SECRETSecret for ISR revalidation
WEBHOOK_SECRETSecret for webhook authentication

WordPress Setup

  1. Enable REST API

    Verify that WordPress REST API is enabled by default

  2. Create Application Password

    User Settings → Application Passwords → Create New

  3. 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');
    });
  4. 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']
      ]);
    });