From 0206900cfff1b44af94f33f95510b18a77f5dd60 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 4 May 2020 10:47:05 +0000 Subject: [PATCH] Canonical: Only redirect non-existing page requests to the post permalink if the post is found. Follow-up to [47760]. See #45337, #40773, #28081, #11694. git-svn-id: https://develop.svn.wordpress.org/trunk@47761 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/canonical.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/canonical.php b/src/wp-includes/canonical.php index 12f7e5e467..08893e16c9 100644 --- a/src/wp-includes/canonical.php +++ b/src/wp-includes/canonical.php @@ -196,10 +196,12 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) { $post_id = $wp_query->post->ID; } - $redirect_url = get_permalink( $post_id ); + if ( $post_id ) { + $redirect_url = get_permalink( $post_id ); - $redirect['path'] = rtrim( $redirect['path'], (int) get_query_var( 'page' ) . '/' ); - $redirect['query'] = remove_query_arg( 'page', $redirect['query'] ); + $redirect['path'] = rtrim( $redirect['path'], (int) get_query_var( 'page' ) . '/' ); + $redirect['query'] = remove_query_arg( 'page', $redirect['query'] ); + } } if ( ! $redirect_url ) {