Skip to main content

Overview

The WPPage 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: 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: source/lib/wordpress.ts:82-94

Mapping WordPress API Response

Converting WordPress REST API data to the WPPage interface:
Source: source/lib/wordpress.ts:5-67

Rendering a WordPress Page

Using the WPPage data in a React component:
Source: source/pages/PageDetail.tsx

Comparison with BlogPost

While WPPage 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.)
The image field may be empty if no featured image is set:

Security Considerations

The content field contains raw HTML from WordPress. Always sanitize or use dangerouslySetInnerHTML with caution. Ensure your WordPress installation is secure and only trusted users can edit pages.

Safe Rendering

Date Localization

Dates are formatted using Spanish locale by default:
To customize for different locales, modify the formatDate function.
  • 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 image field is a string but may be empty ("")
  • The content field contains HTML strings, not React elements
  • Returns null from fetch function if page not found (handle in components)