Skip to main content

Overview

The VENCOL Front Template integrates with WordPress as a headless CMS, fetching content via the WordPress REST API. This approach combines the power of WordPress content management with the performance of a React frontend.

WordPress API Configuration

API Endpoint

The WordPress REST API is configured in lib/wordpress.ts:
wordpress.ts
Update this URL to point to your WordPress installation. Ensure the WordPress REST API is publicly accessible.

Data Types

WordPress Post Interface

Internal interface for raw WordPress API responses:
wordpress.ts

Application Types

Application-friendly interfaces defined in types.ts:
types.ts

Utility Functions

HTML Stripping

WordPress returns titles and excerpts with HTML tags. This function cleans them:
wordpress.ts
Usage:

Date Formatting

Converts WordPress date format to localized Spanish format:
wordpress.ts
Example output: "3 mar 2026"

Data Mapping

Blog Post Mapping

Transforms WordPress post format to application format:
wordpress.ts
Featured images and categories are extracted from the _embedded object when using the _embed query parameter.

Page Mapping

Transforms WordPress page format:
wordpress.ts

API Functions

Fetching Blog Posts

Retrieves multiple blog posts:
wordpress.ts
Usage in components:
Home.tsx

Fetching Pages by Slug

Retrieves a single page by its slug:
wordpress.ts
Usage in PageDetail component:
PageDetail.tsx

WordPress REST API Parameters

The _embed parameter includes related data in the response:
This embeds:
  • Featured images (wp:featuredmedia)
  • Author information (author)
  • Categories and tags (wp:term)

Common Query Parameters

Example:

Error Handling

Graceful Degradation

The application uses fallback data when WordPress is unavailable:
Home.tsx
Always initialize state with fallback data from data.tsx to ensure the site works even if WordPress is down.

404 Handling

When a page is not found:
PageDetail.tsx

Loading States

Display loading skeleton while fetching:
PageDetail.tsx

Rendering WordPress Content

Dangerously Set HTML

WordPress content includes HTML that needs to be rendered:
PageDetail.tsx
Only use dangerouslySetInnerHTML with trusted content from your WordPress CMS. Never use it with user-generated content without sanitization.

Prose Styling

Tailwind Typography plugin provides prose classes for rich content:

WordPress Image Handling

Featured images are extracted from embedded data:

Image Alignment Classes

Custom CSS supports WordPress image alignment:
index.html

SEO Integration

WordPress content is used for SEO metadata:
PageDetail.tsx

Best Practices

Include _embed in API requests to get featured images and categories in a single request:
Always provide fallback data for when WordPress is unavailable:
Implement proper loading UI to improve perceived performance:
WordPress content is trusted in this application, but if you allow user-generated content, implement proper sanitization before rendering HTML.
Define proper TypeScript interfaces for all WordPress data:

Extending the Integration

Adding Custom Post Types

To fetch custom post types:

Adding Custom Fields

If using ACF or custom fields:

Pagination Support

Implement pagination for blog listing:

Architecture

Understand the overall application structure

Routing

Learn about dynamic page routing

Styling

Explore WordPress content styling