The Context
I have a domain, we'll call it example, where traffic travelling to this domain first hits a reverse proxy and depending on the path it is directed to two different containers.
Traffic going to the root path "/" is directed to a static Nuxt page. All other traffic "/*" is directed to the WordPress site.
The end result of this is we have a fast-loading landing page and the rest of the content is managed by WordPress.
We use Elementor for designing the WordPress pages.
The Problem
Published pages, whether public or private, work fine as they appear under something other than the root path e.g. "/somepage". The issue arises with unpublished draft pages that try to use the root path and just append a query string e.g. "/?page_id=1234" - this obviously just redirects to the Nuxt site.
Solution?
I'd think the easy solution would be just to have drafts appear on a custom path e.g. "/draft?page_id=1234". Following this guide, I added some code to the functions.php theme file which uses the preview_post_link hook. Inspecting the preview links, it seems to have worked:
The problem is when clicking the preview or even just visiting the URL with the draft prefix it just redirects back to the root path e.g. example/draft/?page_id=1234&preview=true redirects to example/?page_id=1234. This effectively is redirecting it back to the Nuxt site and fails to show the preview.
Considering this is on page load it must be some JS running on the page. Possibly this is Elementor overriding my custom functionality based on the permalinks but how do I stop this from happening and get it to work under my custom draft path?
For reference here is the snippet I added to the bottom of the functions.php file:
function update_preview_link($link) {
$parts = parse_url($link);
$parts['path'] = "/draft" . $parts['path'];
return $parts['scheme'] . "://" . $parts['host'] . $parts['path'] . (isset($parts['query']) ? "?" . $parts['query'] : "");
}
add_filter('preview_post_link', 'update_preview_link');
add_filter('preview_page_link', 'update_preview_link');