Displaying on your site

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:

  1. Shortcode – Use [apipress id=”123″] in any page, post, or text editor
  2. Template Tag – Use PHP code in your theme template files
  3. 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

[apipress id=”123″]

id is the ID number of the API you created. To find the API ID:

  1. Go to WordPress admin > API Press
  2. Click the API you want to use
  3. Look at the URL: it will show something like ?api_id=123
  4. 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:

[apipress id=”5″]

Override cache duration:

[apipress id=”5″ cache=”3600″]

Bypass SSL (development only):

[apipress id=”5″ ssl_bypass=”true”]

Disable caching for this use:

[apipress id=”5″ cache=”0″]

Enable logging for debugging:

[apipress id=”5″ logging=”true”]

Override the API URL entirely:

[apipress id=”5″ url=”https://different-api.com/endpoint”]
Note: Parameters must be in the correct format. Strings can be quoted or unquoted, and numeric values should be without quotes.

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

  1. Open a page or post in the block editor
  2. Click the “+” button to add a new block
  3. Search for “API Press” or “API Data”
  4. Click the “API Press: API Data” block
  5. Select which API to display from the dropdown
  6. 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

  1. In the block settings, click “Add Attribute”
  2. Enter the attribute name (e.g., “cache”)
  3. Enter the value (e.g., “3600”)
  4. 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

<?php echo do_shortcode( ‘[apipress id=”123″]’ ); ?>

Template Tag with Attributes

You can pass arguments as an array:

<?php $args = array( ‘id’ => 123, ‘cache’ => 3600, ‘timeout’ => 30, ); echo do_shortcode( ‘[apipress id=”‘ . $args[‘id’] . ‘” cache=”‘ . $args[‘cache’] . ‘”]’ ); ?>

Direct PHP Function Call

You can also call the API directly from your theme:

<?php $api_request = APIPRESS_Api_Request::instance(); $result = $api_request->run_api_request( array( ‘api_id’ => 123, ‘cache’ => 3600, ‘timeout’ => 30, ) ); if ( is_array( $result ) ) { echo wp_json_encode( $result ); } ?>

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):

<?php // Display API data with custom cache duration echo do_shortcode( ‘[apipress id=”5″ cache=”7200″]’ ); ?>

Or to display multiple APIs on the same page:

<?php echo ‘<div class=”products”>’; echo do_shortcode( ‘[apipress id=”5″]’ ); echo ‘</div>’; echo ‘<div class=”related”>’; echo do_shortcode( ‘[apipress id=”7″]’ ); echo ‘</div>’; ?>

Common Display Scenarios

Display Latest 10 Products with Cache

[apipress id=”3″ cache=”86400″]

This displays API #3, caching the result for 24 hours (86400 seconds).

Display with Fresh Data (No Cache)

[apipress id=”5″ cache=”0″]

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

<h2>Featured Products</h2> [apipress id=”3″] <h2>Latest Blog Posts</h2> [apipress id=”7″] <h2>Team Members</h2> [apipress id=”12″]

Override Cache per Page

If your API is configured with a 1-hour cache, but you want fresh data on one specific page:

[apipress id=”5″ cache=”0″]

Enable Debugging for Troubleshooting

[apipress id=”5″ logging=”true”]

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:

[apipress id=”5″ cache=”86400″]

For Dynamic Data (News, Prices, Weather)

Cache for a shorter period or disable:

[apipress id=”5″ cache=”1800″]

1800 seconds = 30 minutes. Adjust based on how frequently data changes.

For Real-Time Data (Stock Prices, Live Updates)

Disable caching:

[apipress id=”5″ cache=”0″]

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:

<?php $cache_key = ‘apipress_cache_5’; // Replace 5 with your API ID delete_transient( $cache_key ); ?>

Troubleshooting Display Issues

Shortcode appears as text, not displaying data

Solution: Make sure you are using the correct syntax:

  • Check that id attribute 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:

  1. Test the API connection in the API Press admin (click Test Request)
  2. Verify the API endpoint is correct and accessible
  3. Check authentication credentials if required
  4. Enable logging with logging="true" to see error messages
  5. 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

[apipress id=”5″ logging=”true”]

This will log the request details so you can review what happened.

Preview Request Details

[apipress id=”5″ preview=”true”]

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:

  1. Shortcode: Easiest option for most users [apipress id=”123″]
  2. Block Editor: Use the visual block editor for modern WordPress sites
  3. Template Tag: Most control for developers working with theme files

Configure caching, use the right API endpoint, and test thoroughly for the best results.