WordPress.org

Make WordPress Core


Ignore:
Timestamp:
04/30/2020 12:03:11 PM (21 months ago)
Author:
SergeyBiryukov
Message:

Canonical: Redirect paged requests for non-paginated posts to the post permalink.

This avoids displaying duplicate content of the same post under different URLs and ensures the canonical URL is correct.

Previously, requests for invalid page numbers were only redirected to the post permalink if the post was actually paginated using the <!--nextpage--> marker.

Follow-up to [34492].

Props jeremyfelt, prografika, sachit.tandukar, subrataemfluence, hronak, ekatherine, henry.wright, chesio, dd32, SergeyBiryukov.
Fixes #40773. See #45337, #28081, #11694.

File:
1 edited

Legend:

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

    r47617 r47727  
    158158        }
    159159
    160         if ( get_query_var( 'page' ) && $wp_query->post &&
    161             false !== strpos( $wp_query->post->post_content, '<!--nextpage-->' ) ) {
     160        if ( get_query_var( 'page' ) && $wp_query->post ) {
    162161            $redirect['path']  = rtrim( $redirect['path'], (int) get_query_var( 'page' ) . '/' );
    163162            $redirect['query'] = remove_query_arg( 'page', $redirect['query'] );
Note: See TracChangeset for help on using the changeset viewer.