Once you have configured your API and set up field mapping, you are ready to display the data on your WordPress pages and posts. This article explains how to use shortcodes and template tags to add API data to your site.
Overview
API Press provides two main methods to display API data:
- Shortcode – Use [apipress id=”123″] in any page, post, or text editor
- Template Tag – Use PHP code in your theme template files
- Block Editor – Use the API Press block in the WordPress block editor
Choose the method that works best for your use case.
Method 1: Using the Shortcode
The shortcode is the easiest way to display API data. It works in the visual editor, page builders, and anywhere else shortcodes are supported.
Basic Shortcode Syntax
id is the ID number of the API you created. To find the API ID:
- Go to WordPress admin > API Press
- Click the API you want to use
- Look at the URL: it will show something like
?api_id=123 - That number (123) is your API ID
Full Shortcode Attributes
The basic shortcode uses the settings you configured in the API Press admin. However, you can override any setting directly in the shortcode:
| Attribute | Type | Description |
|---|---|---|
| id | Number | API ID (required). The ID of the API to use. |
| method | Text | Override the HTTP method (GET, POST, PUT, DELETE, PATCH) |
| url | URL | Override the API endpoint URL |
| timeout | Number | Override the request timeout in seconds |
| cache | Number | Override cache duration in seconds. Set to 0 for no cache. |
| ssl_bypass | Text | Set to “true” to bypass SSL certificate verification (development only) |
| logging | Text | Set to “true” to log this request for debugging |
| preview | Text | Set to “true” to show request details (for debugging) |
Shortcode Examples
Basic usage:
Override cache duration:
Bypass SSL (development only):
Disable caching for this use:
Enable logging for debugging:
Override the API URL entirely:
Method 2: Using the Block Editor
If you are using the WordPress block editor (Gutenberg), you can add an API Press block to your page or post.
How to Add the Block
- Open a page or post in the block editor
- Click the “+” button to add a new block
- Search for “API Press” or “API Data”
- Click the “API Press: API Data” block
- Select which API to display from the dropdown
- Configure any custom options if needed
Block Options
The API Press block has these options:
- API Selection – Choose which API to display
- Custom Shortcode Attributes – Add custom attributes to override API settings (same as shortcode attributes)
Adding Custom Attributes in the Block
- In the block settings, click “Add Attribute”
- Enter the attribute name (e.g., “cache”)
- Enter the value (e.g., “3600”)
- Click the add button to save
This is equivalent to using the shortcode with attributes: [apipress id="123" cache="3600"]
Method 3: Using the Template Tag
If you are a developer comfortable editing theme files, you can use the template tag function to display API data in your theme template files.
Basic Template Tag Syntax
Template Tag with Attributes
You can pass arguments as an array:
Direct PHP Function Call
You can also call the API directly from your theme:
Template Tag Attributes
When using the template tag, you can pass the same attributes as the shortcode:
| Parameter | Type | Description |
|---|---|---|
| api_id | Number | The API ID to use (required) |
| method | Text | HTTP method (GET, POST, etc.) |
| url | URL | Custom API endpoint URL |
| timeout | Number | Request timeout in seconds |
| cache | Number | Cache duration in seconds |
| headers | Array | Custom HTTP headers |
| params | Array | Query parameters |
| body | Array | Request body data |
Example: Using Template Tag in a Theme File
To display API data in a custom theme template file (like header.php or footer.php):
Or to display multiple APIs on the same page:
Common Display Scenarios
Display Latest 10 Products with Cache
This displays API #3, caching the result for 24 hours (86400 seconds).
Display with Fresh Data (No Cache)
Set cache to 0 to fetch fresh data every time the page loads. Useful for real-time data like weather or stock prices.
Display Multiple APIs on Same Page
Override Cache per Page
If your API is configured with a 1-hour cache, but you want fresh data on one specific page:
Enable Debugging for Troubleshooting
This logs detailed request information. Check the API Press logs in the WordPress admin under API Press > Logs.
Caching Strategy
Caching significantly improves performance but can show outdated data. Choose the right strategy:
For Static Data (Products, Team Members)
Cache for 24 hours or more:
For Dynamic Data (News, Prices, Weather)
Cache for a shorter period or disable:
1800 seconds = 30 minutes. Adjust based on how frequently data changes.
For Real-Time Data (Stock Prices, Live Updates)
Disable caching:
Note: Disabling cache increases load on both your server and the external API.
Clearing Cache Manually
Cache is automatically cleared when you save your API settings. To clear cache programmatically:
Troubleshooting Display Issues
Shortcode appears as text, not displaying data
Solution: Make sure you are using the correct syntax:
- Check that
idattribute is present and contains a valid API ID - Verify no spelling mistakes in [apipress]
- Ensure the API with that ID exists and is published
Data not displaying after configuring API
Solution:
- Test the API connection in the API Press admin (click Test Request)
- Verify the API endpoint is correct and accessible
- Check authentication credentials if required
- Enable logging with
logging="true"to see error messages - Check WordPress error logs
Blank page or white screen of death
Solution: The API request may be timing out or causing an error:
- Increase timeout:
[apipress id="5" timeout="60"] - Test on a smaller data set (add limit parameter to API)
- Enable debug mode to see error messages
Data shows but formatting is wrong
Solution: Check your field mapping and transforms in the API Press admin:
- Verify each field is mapped to the correct API response field
- Check that transforms are spelled correctly
- Test the API response structure
Images not displaying
Solution:
- Verify image URLs are complete and start with https://
- Check that images are publicly accessible
- Use
ensure_prefix:https://transform if needed - Check browser console for CORS or mixed content errors
Performance is slow
Solution:
- Enable caching:
[apipress id="5" cache="3600"] - Reduce the amount of data returned (use API parameters to limit results)
- Increase timeout if API is slow to respond
- Check if external API is slow or offline
Debugging API Requests
View Request Logs
Go to WordPress admin > API Press > Logs to see all API requests. This shows:
- Request URL and method
- Response status code
- Response time
- Error messages
Enable Logging for a Specific Request
This will log the request details so you can review what happened.
Preview Request Details
Shows debugging information about the request and response on the page (admin only). Useful for development and troubleshooting.
Best Practices
- Always cache when possible: Improves performance and reduces load on external APIs
- Use descriptive API names: Makes it easier to identify which API to use
- Test thoroughly: Check that data displays correctly before going live
- Monitor your API calls: Watch the logs to ensure requests are working
- Keep credentials secure: Never share API keys in public code or comments
- Provide fallback content: Consider what to show if the API is unavailable
- Use timeouts appropriately: Balance between performance and reliability
Summary
You now have three ways to display API data on your site:
- Shortcode: Easiest option for most users [apipress id=”123″]
- Block Editor: Use the visual block editor for modern WordPress sites
- Template Tag: Most control for developers working with theme files
Configure caching, use the right API endpoint, and test thoroughly for the best results.
