The Static Site Generator (SSG) is one of the most powerful features in WP SSR Framework. Because the frontend is a React SPA, search engine crawlers and AI agents would normally see a blankDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Ahondev/portfolio-v2/llms.txt
Use this file to discover all available pages before exploring further.
<div id="root"> — missing all your content. SSG solves this by calling an external headless-browser render API, saving the fully-rendered HTML to disk, and serving it directly to bots via the BotDetector middleware, while human visitors continue to enjoy the fast client-side SPA experience.
How SSG Works
Build the URL from the post
StaticSiteGeneratorService::generatePostHTML(WP_Post $post) resolves the correct public URL for the post. For WordPress pages it uses WebRouter::slugToPath() combined with get_home_url(); for custom post types it calls get_post_permalink().Call the headless-browser render API
generateHTML(string $url): string POSTs to the external render API with a WEB_RENDER_TOKEN Bearer token. The request waits for the network to go idle, uses a 1440×900 viewport, and requests French locale content.{ "success": true, "html": "..." }. Any non-2xx response or missing html key throws a RuntimeException.Store the HTML file and update post meta
storeHTML(WP_Post $post, string $html): string writes the rendered HTML to /cache/client/static/{slug}.html and records three post-meta keys for cache-invalidation tracking.Serve static HTML to bots
On every front-end request,
BotDetector::isBot() inspects the User-Agent header against a curated list of known crawlers (Googlebot, GPTBot, facebookexternalhit, and dozens more). If a bot is detected and a cached file exists, WordPress serves the pre-rendered HTML directly with an X-SSG-Cache: HIT response header and full 304 Not Modified support. Human visitors — and any request with ?json=1 — always bypass the static cache and hit the live SPA.You can add your own crawler patterns by hooking into the
ahon_is_bot filter and returning true.Cache Lifecycle Methods
| Method | Description |
|---|---|
generatePostHTML(WP_Post $post) | Full pipeline: resolve URL → render → store |
generateHTML(string $url) | Call the render API and return raw HTML |
storeHTML(WP_Post $post, string $html) | Write file + update post meta |
deleteCachedFile(WP_Post $post) | Remove .html file + delete all three post-meta keys |
clearAll() | Wipe every file in /cache/client/static/ + bulk-delete post meta via $wpdb |
getCacheableItems() | Return an array of all cacheable posts with their cache status |
getCacheableItems() return shape
WP Admin Dashboard
The SSG dashboard lives at WP Admin → SSG (admin.php?page=ssg-dashboard). It is registered by SSGServiceProvider and requires the manage_options capability.
Generate & Clear
”⚡ Generate All Pages” iterates every cacheable item and calls the render API in sequence, with a live progress bar and scrollable log. “🗑️ Clear All Cache” wipes all files and post meta in one click.
Bulk Actions
Select individual rows and use ”🔄 Regenerate Selected” or “🗑️ Delete Selected” to operate on a subset of pages. The counter badge updates live as you tick checkboxes.
Daily Cron
A checkbox toggles a WordPress cron event (
ssg_daily_generation) that regenerates all pages once daily via wp_schedule_event. Uncheck to cancel the schedule.Admin Bar Status
A persistent indicator in the WP admin bar shows ✅ SSG: Complete (green) or ⚠️ SSG: Need Generation (pulsing red) so you can spot stale caches at a glance without opening the dashboard.
REST API
SSGController exposes three authenticated endpoints under /api/v1/ssg/. All requests must include a valid X-WP-Nonce header.
- Generate single page
- Generate all pages
- Delete cached file
Environment Variable
SetWEB_RENDER_TOKEN in your .env file before using SSG. The service throws a RuntimeException at generation time if the variable is missing.
Related Pages
SEO Management
Populate ACF SEO fields so every pre-rendered page has the correct title, description, and OG image.
Caching
Understand the transient cache layer that complements SSG for dynamic API data.