---
title: Overriding home_url() and site_url() for headless WordPress setups on Pressable
url: "https://pressable.com/knowledgebase/overriding-home_url-and-site_url-for-headless-wordpress-setups-on-pressable/"
published: 2025-06-04
modified: 2025-09-11
author: Nox Dineen-Porter
---

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:

1. Connect to your site’s file system (via [SSH](https://pressable.com/knowledgebase/connect-to-ssh-on-pressable/), [SFTP](https://pressable.com/knowledgebase/setup-and-use-sftp-to-connect-to-your-wordpress-site/) or a [file manager plugin](https://pressable.com/knowledgebase/using-wp-file-manager-with-pressable/))
2. Create a file in `/wp-content/mu-plugins/` named something like `override-home-url.php`
3. 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()` or `site_url()`
- You’re not relying on `WP_HOME`/`WP_SITEURL` constants 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.
