WordPress set up
Store Your MLS API Key in WordPress
Where WordPress keeps secrets, how a WordPress plugin's PHP code reads the key, and how to check it never reaches the page.
Part of the WordPress MLS API Integration guide · Last reviewed 2026-11-20

In WordPress, the safest simple place for the key is wp-config.php, the configuration file that WordPress reads on the server before anything else. Add define( 'SAIGE_MLS_API_KEY', 'your-key' ); and define( 'SAIGE_MLS_API_URL', 'feed-address' ); above the line that says to stop editing. PHP reads the constants, and they are never sent to browsers. If your host lets you set server environment variables, that works too.
Key takeaways
- Add two define lines to wp-config.php.
- Only plugin PHP reads them.
- Never print them in page HTML or JavaScript.
- Keep wp-config.php out of any public Git repository.
Need the data feed for this? Saige is an approved MLS data vendor in BC. Send a request and our team will contact you.
Where WordPress keeps secrets
wp-config.php sits in the WordPress root folder. Edit it with your host's file manager or SFTP. Put the lines above the comment that says to stop editing.
- Open wp-config.php in the WordPress root folder.
- Add: define( 'SAIGE_MLS_API_KEY', 'your-key' );
- Add: define( 'SAIGE_MLS_API_URL', 'feed-address' );
- Save, and check the site still loads.
Reading the key in a WordPress plugin's PHP code
The plugin reads the constants and calls the feed with wp_remote_get, WordPress's HTTP function. The answer is cached with set_transient, so repeated page views reuse it for a set time.
<?php
/*
Plugin Name: Saige MLS Listings
Description: Reads listings from the Saige MLS feed on the server.
*/
if ( ! defined( 'ABSPATH' ) ) exit;
// SAIGE_MLS_API_KEY and SAIGE_MLS_API_URL are defined in wp-config.php.
function saige_mls_get( $args, $cache_seconds = 600 ) {
$query = http_build_query( $args, '', '&', PHP_QUERY_RFC3986 );
$cache_key = 'saige_mls_' . md5( $query );
$cached = get_transient( $cache_key );
if ( false !== $cached ) return $cached;
$res = wp_remote_get( SAIGE_MLS_API_URL . '/Property?' . $query, array(
'headers' => array( 'Authorization' => 'Bearer ' . SAIGE_MLS_API_KEY ),
'timeout' => 15,
) );
if ( is_wp_error( $res ) || 200 !== wp_remote_retrieve_response_code( $res ) ) {
error_log( 'Saige MLS feed error' );
return array();
}
$data = json_decode( wp_remote_retrieve_body( $res ), true );
$listings = isset( $data['value'] ) ? $data['value'] : array();
set_transient( $cache_key, $listings, $cache_seconds );
return $listings;
}Check before you publish
Open the published WordPress site, view the page source, and search for the first characters of your key. It must not be there. Then use the search page with the browser's network panel open: requests should go to your own server code, not straight to the feed address. The full check list is at Keep Your MLS API Key Secret on an AI-Built Site.
Frequently asked questions
Can I put the key in a plugin's settings page?
You can, but settings are stored in the database and may be shown to anyone with admin access. wp-config.php keeps it out of the admin screens.
How long should the cache last?
Short enough to meet your board's rule on how fresh listings must be. Our team covers that rule when we contact you.
Related pages in this guide
Sources
Every claim on this page that could be checked against a primary source is linked below. Where something is not publicly documented by a vendor, the page says so rather than filling the gap with an estimate.
- HTTP API (WordPress.org)
- Transients API (WordPress.org)
- wp-config.php (WordPress.org)
- Secrets Management Cheat Sheet (OWASP Foundation)