If you’re using WordPress in a headless setup (where the WordPress backend powers a decoupled frontend hosted elsewhere), you may want WordPress to return your frontend URL when generating links via home_url() or site_url().
However, defining WP_HOME and WP_SITEURL in wp-config.php doesn’t always produce the expected result on Pressable.
Why overriding WP_HOME doesn’t work on Pressable
At Pressable, our platform may define WP_HOME and WP_SITEURL before WordPress fully loads. This means attempts to override these constants later in wp-config.php have no effect.
Fortunately, WordPress uses the home and siteurl options internally when calling functions like home_url() and get_home_url(). These option values can be filtered at runtime, which gives us a clean workaround.
The solution: use a must-use plugin to override URLs
A must-use (mu) plugin is a type of plugin that loads automatically and cannot be disabled via the WordPress admin. It’s ideal for critical runtime overrides like this.
To force WordPress to return your frontend URL:
- Connect to your site’s file system (via SSH, SFTP or a file manager plugin)
- Create a file in
/wp-content/mu-plugins/named something likeoverride-home-url.php - Add the following code to that file, replacing the example URL with your actual frontend domain:
<?php
// /wp-content/mu-plugins/override-home-url.php
add_filter('option_home', function() {
return 'https://your-frontend-domain.com';
});
add_filter('option_siteurl', function() {
return 'https://your-frontend-domain.com';
});
add_filter('home_url', function($url, $path = '', $orig_scheme = null, $blog_id = null) {
return rtrim('https://your-frontend-domain.com', '/') . $path;
}, 10, 4);
NOTE: Remember to replace https://your-frontend-domain.com with the actual front-end domain for your web app.
When should you use this approach?
This override is appropriate only if:
- You’re running WordPress in a headless configuration
- You need WordPress to return a different frontend URL for output functions like
home_url()orsite_url() - You’re not relying on
WP_HOME/WP_SITEURLconstants to enforce the site’s primary URL
Do not use this method on traditional WordPress setups—it will result in unexpected behavior or broken links.