最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - Unpublished Pages Failing To Appear On Custom Path

programmeradmin2浏览0评论

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');
发布评论

评论列表(0)

  1. 暂无评论