WordPress.org

Make WordPress Core

Changeset 47761


Ignore:
Timestamp:
05/04/2020 10:47:05 AM (3 months ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/canonical.php

    r47760 r47761  
    197197            }
    198198
    199             $redirect_url = get_permalink( $post_id );
    200 
    201             $redirect['path']  = rtrim( $redirect['path'], (int) get_query_var( 'page' ) . '/' );
    202             $redirect['query'] = remove_query_arg( 'page', $redirect['query'] );
     199            if ( $post_id ) {
     200                $redirect_url = get_permalink( $post_id );
     201
     202                $redirect['path']  = rtrim( $redirect['path'], (int) get_query_var( 'page' ) . '/' );
     203                $redirect['query'] = remove_query_arg( 'page', $redirect['query'] );
     204            }
    203205        }
    204206
Note: See TracChangeset for help on using the changeset viewer.