Unparalleled suite of productivity-boosting Web APIs & cloud-based micro-service applications for developers and companies of any size.


API Integration: How to Integrate API Into WordPress Page

A developer is searching APILayer for API Integration

It’s important to have an API in an application these days, given how sophisticated some applications are. When you do API integration into WordPress, it allows you to access real-time information, automate content updates, and provide interactive features. However, there are certain things you need to know to get started with this. This article will go through how you can integrate API in WordPress.

What’s the Difference Between Theme and Plugin API Integration in WordPress?

There are two main ways of integrating APIs in WordPress. One is by Themes and the other by Plugins. Each of these ways has its own pros and cons.

Themes, for instance, provide you with a flexible means of customizing the design and layout of your WordPress site. They offer a variety of templates and styles from which to choose. You must modify the theme files in order to integrate API calls and display the necessary material in order to implement the API call integration via a theme. This method definitely has its own advantages. For example, they are quite simple since it has very few steps as opposed to creating a WordPress REST API plugin from scratch.

This article will focus primarily only on how you can integrate APIs through Themes.

Step-By-Step Guide to Integrating an External API Into WordPress

This step-by-step guide will go through how you can integrate your external API into WordPress. But first, you have to choose an API. This article will demonstrate using the currencylayer API from API Layer. Access to historical and current exchange rates for different currencies is made possible via the currencylayer API. Developers can access precise and recent exchange rates for a variety of global currencies.

1. Obtain an API Key for the External API

Like it is for all APIs, we should get an API key for the currencylayer API as well. This key will be a unique identifier that gives access to API data endpoints.

Obtain an API Key for API Integration

First, sign up for an account in currencylayer. You can subscribe to the free version for 100 API calls.

You will then get access to a free API key in your dashboard.

Use your key and append it to a base URL. The following URL is an example to get live currency rates.

2. Create a Child Theme

Using a child theme is of utmost importance when it comes to maintaining the integrity and flexibility of your WordPress website. It acts as a safeguarding layer that allows you to make customizations without altering the original parent theme. The significance of using a child theme can be attributed to several key factors.

Firstly, a child theme ensures that any modifications you make to your website won’t be lost when the parent theme is updated. It acts as a protective shield, preserving your customizations and preventing them from being overwritten. This way, you can confidently update the parent theme without the fear of losing your changes.

Furthermore, a child theme grants you the freedom to customize various aspects of your website, including design, layout, and functionality. It empowers you to make changes without any limitations imposed by the parent theme. With a child theme, you have complete control over the customization process.

Before we create the child theme, make sure you have properly hosted your WordPress site.

Steps to Create a Child Theme

Go to your WordPress theme directory. You can usually find this directory when you navigate into the wp-content directory and then into themes.

Access WordPress theme directory for API Integration

If you notice a theme folder already inside (which usually is the case) like the one in the image above, create another folder in that same directory. You can name this with a “child” prefix to the existing theme folder, eg. “twentytwentyone-child”.

Child theme for API Integration

Now, in this child theme folder, create a file (not a folder) with the name style.css. In this file, you can add the following code.

You should also make sure the “twentytwentyone” in the Template matches with the parent theme folder.

twentytwentyone child


To make sure the stylesheet is usable, we need to enqueue it. We can do so by creating another file alongside the style.css file with the name “functions.php” and adding the following.


Now to activate this theme, go to your WordPress admin area and navigate into Appearance and into Themes.

Appearance and into Themes.

You will be able to see the theme you created previously on your screen. You can now click on “Activate”.

3. Create a Custom Page Template and Integrate the API

We created a theme, and now we will be using a custom page template so that it structures your webpage in a way that integrates your own API request data appropriately.

To get started, create another file with the name “custom-api.php” under your child theme directory. Paste the following code but make sure to replace the access key appropriately.

The following image shows you how the above code appears on the file.

4. Add a New Page Using Your New Page Template

If you now go to your WordPress admin area again, you will find a “Add New” option.

Add a New Page Using Your New Page Template

You will now see a screen where you can find the custom page you created from a template option’s drop-down menu. Select the “Currency Exchange Rates” option.

Currency Exchange Rates

Now you are done! You have now integrated your currency exchange rates WordPress REST API into your WordPress site.


How to Handle REST API Authentication in WordPress?

Securing API authentication in WordPress is very important when integrating APIs into your website. It ensures that only authorized users or applications can access and interact with the API.

Using unique API keys is a common approach. These keys act as identifiers that grant access to the API. You can obtain an API key from the provider and securely store it in your WordPress installation. When making API requests, include the key as a parameter or in the request headers.

OAuth is a widely adopted protocol for authentication and authorization. It enables users to grant limited access to their data on one platform (e.g., WordPress) to another (e.g., the API provider). A WordPress plugin would simplify the implementation of OAuth for API authentication.

Another method is token-based authentication, where authorized users or applications receive a token. This token serves as proof of authentication and should be included in API requests. WordPress provides plugins and libraries supporting token-based authentication methods like JWT.

Consider implementing two-factor authentication (2FA) for enhanced security. With 2FA, users must provide an additional authentication factor, such as a code sent to their mobile device, along with their credentials.

Why Should You Use APILayer for Your Next API Search?

Integrating APIs into your WordPress pages opens up a world of possibilities, allowing you to leverage external services and data to enhance your website’s functionality. By following the methods discussed in this article, such as using themes or plugins, you can seamlessly incorporate APIs and access real-time information, automate content updates, and provide interactive features.

For your next API search, APILayer is the ideal choice. As an API marketplace, APILayer offers a wide range of APIs that cater to various needs and industries. Whether you require currency conversion, WordPress data, payment processing, or any other functionality, APILayer has you covered.

Visit APILayer now to explore their extensive collection of APIs and take your website to the next level.


Can We Integrate API in WordPress?

Yes. You can integrate APIs in WordPress. There are two main ways. One is by using themes, and the other is by plugins.

What Is API Integration?

API integration is the process of connecting software applications with external APIs in order to exchange data or functionality.

Can I Integrate Multiple APIs Into My WordPress Website?

Yes. WordPress offers the flexibility to integrate multiple APIs.

Are There Any Costs Associated With API Integration WordPress?

The cost of API integration depends on the API provider you choose. While some APIs provide free access with limited functionality, you will need to purchase a subscription or license to gain more advanced functionality.

Related posts

Flight Dashboard and Tracker Development Using Aviationstack


A Step-by-Step Guide To An Exchange Rate API


Access Key – What is Access Key?


How to Easily Implement "Did You Mean This" in Your App?

Leave a Reply

Your email address will not be published. Required fields are marked *