Make WordPress Core


Ignore:
Timestamp:
05/04/2020 10:40:06 AM (21 months ago)
Author:
SergeyBiryukov
Message:

Canonical: Redirect paged requests for a static page assigned as the "Posts page".

This avoids displaying duplicate content of the home page under different URLs with appended page numbers.

This change only affects the <!--nextpage--> pagination (page query variable) and not the regular multiple posts pagination (paged query variable).

The posts page does not support the <!--nextpage--> pagination, so requests for invalid page numbers should be redirected to the page permalink, applying the logic previously implemented for single posts or pages.

Follow-up to [34492], [47727].

Props jeremyfelt, sachit.tandukar, SergeyBiryukov.
Fixes #45337. See #40773, #28081, #11694.

File:
1 edited

Legend:

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

    r47738 r47760  
    671671            $content_found = true;
    672672
    673             $post = isset( $wp_query->post ) ? $wp_query->post : null;
    674 
    675             // Only set X-Pingback for single posts that allow pings.
    676             if ( is_singular() && $post && pings_open( $post ) && ! headers_sent() ) {
    677                 header( 'X-Pingback: ' . get_bloginfo( 'pingback_url', 'display' ) );
    678             }
    679 
    680             // Check for paged content that exceeds the max number of pages.
    681673            if ( is_singular() ) {
     674                $post = isset( $wp_query->post ) ? $wp_query->post : null;
     675
     676                // Only set X-Pingback for single posts that allow pings.
     677                if ( $post && pings_open( $post ) && ! headers_sent() ) {
     678                    header( 'X-Pingback: ' . get_bloginfo( 'pingback_url', 'display' ) );
     679                }
     680
     681                // Check for paged content that exceeds the max number of pages.
    682682                $next = '<!--nextpage-->';
    683683                if ( $post && ! empty( $this->query_vars['page'] ) ) {
     
    692692            }
    693693
     694            // The posts page does not support the <!--nextpage--> pagination.
     695            if ( $wp_query->is_posts_page && ! empty( $this->query_vars['page'] ) ) {
     696                $content_found = false;
     697            }
     698
    694699            if ( $content_found ) {
    695700                $set_404 = false;
Note: See TracChangeset for help on using the changeset viewer.