mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 12:50:28 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@47760 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -186,6 +186,22 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) {
|
||||
);
|
||||
}
|
||||
|
||||
// Strip off non-existing <!--nextpage--> links from single posts or pages.
|
||||
if ( get_query_var( 'page' ) ) {
|
||||
$post_id = 0;
|
||||
|
||||
if ( $wp_query->queried_object instanceof WP_Post ) {
|
||||
$post_id = $wp_query->queried_object->ID;
|
||||
} elseif ( $wp_query->post ) {
|
||||
$post_id = $wp_query->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'] );
|
||||
}
|
||||
|
||||
if ( ! $redirect_url ) {
|
||||
$redirect_url = redirect_guess_404_permalink();
|
||||
|
||||
@@ -197,14 +213,6 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Strip off non-existing page links from single posts or pages.
|
||||
if ( get_query_var( 'page' ) && $wp_query->post ) {
|
||||
$redirect['path'] = rtrim( $redirect['path'], (int) get_query_var( 'page' ) . '/' );
|
||||
$redirect['query'] = remove_query_arg( 'page', $redirect['query'] );
|
||||
|
||||
$redirect_url = get_permalink( $wp_query->post->ID );
|
||||
}
|
||||
} elseif ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) {
|
||||
|
||||
// Rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101.
|
||||
|
||||
Reference in New Issue
Block a user