Overview
The VENCOL Front Template uses WordPress REST API to fetch blog posts and pages. The integration is already set up inlib/wordpress.ts.
WordPress API Configuration
The WordPress API endpoint is configured inlib/wordpress.ts:
lib/wordpress.ts
Updating the WordPress URL
1
Open lib/wordpress.ts
Locate the
WP_API_URL constant at the top of the file2
Replace with your WordPress URL
lib/wordpress.ts
3
Test the connection
Visit
https://your-wordpress-site.com/wp-json/wp/v2/posts in your browser to verify the API is accessibleThe WordPress REST API is enabled by default in WordPress 4.7+. No plugins required for basic functionality.
Available WordPress Functions
The template provides two main functions for fetching content:1. Fetch Blog Posts
lib/wordpress.ts
YourComponent.tsx
2. Fetch Page by Slug
lib/wordpress.ts
YourComponent.tsx
Data Mapping
WordPress API responses are automatically transformed to match the application’s types:BlogPost Type
types.ts
WPPage Type
types.ts
WordPress Setup Checklist
1
Ensure REST API is enabled
Visit
your-site.com/wp-json - you should see JSON output2
Configure permalinks
In WordPress Admin: Settings → Permalinks → Choose “Post name”
3
Enable featured images
Ensure your theme supports featured images (post thumbnails)
4
Configure CORS (if needed)
If your WordPress site is on a different domain, enable CORS
5
Create categories
Add categories to organize your blog posts (e.g., “Educativo”, “Tecnología”)
Enabling CORS for Cross-Domain Access
If your WordPress site is on a different domain than your frontend, you’ll need to enable CORS.Option 1: Using a Plugin
Install the “REST API CORS Headers” plugin from the WordPress plugin directory.Option 2: Adding to functions.php
Add this to your theme’sfunctions.php:
functions.php
Creating Blog Posts in WordPress
1
Create a new post
In WordPress Admin: Posts → Add New
2
Add title and content
Write your post title and content using the WordPress editor
3
Set featured image
Set a featured image (recommended: 1200x800px, WebP or JPG)
4
Add excerpt
Write a custom excerpt (max 160 characters recommended)
5
Assign category
Select a category (e.g., “Educativo”, “Tecnología”, “Seguridad”)
6
Publish
Click Publish - the post will appear on your frontend automatically
Testing the Integration
1. Test API Endpoint
Open your browser and visit:2. Test in Your Application
Create a test component:TestWordPress.tsx
Fallback to Static Content
The application includes fallback blog posts indata/data.tsx. If WordPress is unavailable:
data/data.tsx
YourBlogPage.tsx
Advanced: Custom Post Types
To fetch custom post types from WordPress:lib/wordpress.ts
Environment Variables (Optional)
For better configuration management, move the API URL to an environment variable:1
Create .env file
2
Update lib/wordpress.ts
lib/wordpress.ts
3
Update vite.config.ts (if needed)
The environment variable will be automatically available via
import.meta.envTroubleshooting
Posts Not Loading
- Check API URL: Verify the URL is correct and accessible
- Check CORS: Look for CORS errors in browser console
- Check WordPress version: Ensure WordPress 4.7+ is installed
- Check permalinks: “Post name” structure is recommended
Featured Images Not Showing
- Ensure
_embedparameter is included in API calls - Check that featured images are set in WordPress
- Verify image URLs are publicly accessible
Categories Not Appearing
- Ensure posts have assigned categories
- Check that
_embedparameter is included - Verify the category taxonomy is
category(default)
Security Considerations
Best Practices
- Never expose WordPress admin credentials in frontend code
- Use HTTPS for all API requests
- Implement rate limiting on your WordPress server
- Keep WordPress and plugins updated
- Use a CDN for media files
Next Steps
- Customize your site branding and content
- Add new solutions to your catalog
- Deploy to production with Vercel or Netlify