From 4ba6e55e76b9b1c7c60da383c88e1ab79e6c77e3 Mon Sep 17 00:00:00 2001 From: Filip Ilic Date: Thu, 2 Apr 2026 11:30:51 +0200 Subject: [PATCH 1/2] Fix ?format=markdown returning blog posts instead of static front page content When a site uses a static front page, the ?format=markdown query parameter caused WordPress to not recognize the request as singular, falling back to the blog post index. Now detects the static front page via is_front_page() and page_on_front option when is_singular() fails. Closes #35 Co-Authored-By: Claude Opus 4.6 (1M context) Signed-off-by: Filip Ilic --- src/Router/RewriteHandler.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Router/RewriteHandler.php b/src/Router/RewriteHandler.php index e7220a1..c231f9a 100644 --- a/src/Router/RewriteHandler.php +++ b/src/Router/RewriteHandler.php @@ -247,11 +247,21 @@ public function handle_format_parameter(): void { return; } - if (!is_singular()) { - return; - } + $post = null; - $post = get_queried_object(); + if (is_singular()) { + $post = get_queried_object(); + } elseif ('page' === get_option('show_on_front')) { + // Static front page: the extra ?format= query var can prevent + // WordPress from recognising the request as singular, so it falls + // back to the blog-post index. + if (is_front_page() || is_home()) { + $page_on_front = (int) get_option('page_on_front'); + if ($page_on_front) { + $post = get_post($page_on_front); + } + } + } if (!$post instanceof WP_Post) { return; From 80714068752a44407bc6e4d8119b81e3fe093bd5 Mon Sep 17 00:00:00 2001 From: Filip Ilic Date: Thu, 2 Apr 2026 13:37:30 +0200 Subject: [PATCH 2/2] Flatten nested if into single elseif condition Co-Authored-By: Claude Opus 4.6 (1M context) Signed-off-by: Filip Ilic --- src/Router/RewriteHandler.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Router/RewriteHandler.php b/src/Router/RewriteHandler.php index c231f9a..fe58fad 100644 --- a/src/Router/RewriteHandler.php +++ b/src/Router/RewriteHandler.php @@ -251,15 +251,13 @@ public function handle_format_parameter(): void { if (is_singular()) { $post = get_queried_object(); - } elseif ('page' === get_option('show_on_front')) { + } elseif ('page' === get_option('show_on_front') && (is_front_page() || is_home())) { // Static front page: the extra ?format= query var can prevent // WordPress from recognising the request as singular, so it falls // back to the blog-post index. - if (is_front_page() || is_home()) { - $page_on_front = (int) get_option('page_on_front'); - if ($page_on_front) { - $post = get_post($page_on_front); - } + $page_on_front = (int) get_option('page_on_front'); + if ($page_on_front) { + $post = get_post($page_on_front); } }