Function Signature
WPPage format.
Parameters
The URL-friendly slug of the WordPress page to fetch. The slug is automatically URL-encoded to handle special characters.
Return Type
Returns a Promise that resolves to a
WPPage object if found, or null if no page matches the slug.Behavior
- Makes a GET request to the WordPress REST API
/pagesendpoint - Includes
_embedparameter to fetch related media data - URL-encodes the slug parameter for safe transmission
- Returns
nullif no page is found with the given slug - Strips HTML tags from title and excerpt fields
- Formats dates using Spanish locale (es-ES)
- Returns empty string for image if featured media is not available
- Throws an error if the API request fails
Error Handling
Throws an error with the format:Usage Example
Basic Usage
With Null Checking
Router Integration
With Try-Catch
API Endpoint
The function connects to:Related
- fetchBlogPosts - Fetch multiple blog posts
- WPPage Type - Type definition for WordPress page objects