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/class-wp.php

    r47550 r47727  
    679679                // Check for paged content that exceeds the max number of pages.
    680680                $next = '<!--nextpage-->';
    681                 if ( $p && false !== strpos( $p->post_content, $next ) && ! empty( $this->query_vars['page'] ) ) {
    682                     $page    = trim( $this->query_vars['page'], '/' );
    683                     $success = (int) $page <= ( substr_count( $p->post_content, $next ) + 1 );
     681                if ( $p && ! empty( $this->query_vars['page'] ) ) {
     682                    // Check if content is actually intended to be paged.
     683                    if ( false !== strpos( $p->post_content, $next ) ) {
     684                        $page    = trim( $this->query_vars['page'], '/' );
     685                        $success = (int) $page <= ( substr_count( $p->post_content, $next ) + 1 );
     686                    } else {
     687                        $success = false;
     688                    }
    684689                }
    685690            }
Note: See TracChangeset for help on using the changeset viewer.