Overview
TheWPPage interface represents a static page fetched from the WordPress CMS. It’s used for dynamic content pages that are managed in WordPress but rendered in the React application, providing flexibility for content updates without code deployments.
Type Definition
source/types.ts:45-52
Properties
number
required
Unique WordPress page ID from the CMS database. Used for identification and caching.
string
required
URL-friendly page identifier. Matches the WordPress slug and is used for routing in the React app.
string
required
The page title, typically displayed as an H1 heading. HTML entities are stripped during mapping.
string
required
Full HTML content of the page. Contains rich text, images, and any WordPress block editor content.
string
required
Short summary or description of the page. HTML is stripped for plain text use in meta tags.
string
required
Publication or last modified date in localized format (e.g.,
"3 feb. 2024").string
required
URL of the featured image. May be an empty string if no featured image is set in WordPress.
Usage Examples
Fetching WordPress Pages
The primary use case is fetching pages from WordPress REST API:source/lib/wordpress.ts:82-94
Mapping WordPress API Response
Converting WordPress REST API data to theWPPage interface:
source/lib/wordpress.ts:5-67
Rendering a WordPress Page
Using theWPPage data in a React component:
source/pages/PageDetail.tsx
Comparison with BlogPost
WhileWPPage and BlogPost have similar structures, they serve different purposes:
API Integration Notes
The
WPPage interface is designed to work with the WordPress REST API v2. Ensure your WordPress site has the REST API enabled and publicly accessible.Required WordPress API Parameters
When fetching pages, use these query parameters:slug- Filter by page slug_embed- Include embedded data (featured media, authors, etc.)
Handling Missing Featured Images
Theimage field may be empty if no featured image is set:
Security Considerations
Safe Rendering
Date Localization
Dates are formatted using Spanish locale by default:formatDate function.
Related Types
- BlogPost - Similar structure for blog posts with additional category field
- Service - Another content type for product/service pages
TypeScript Notes
- All properties are required (non-optional)
- The
imagefield is a string but may be empty ("") - The
contentfield contains HTML strings, not React elements - Returns
nullfrom fetch function if page not found (handle in components)