hi,
sorry for tagging.
here is the issue:
1. with the default post archive URL with category prefix, everything is fine. i.e. abc.com/category/news, page-1, page-2 all self-canonical and with prev/next rel link.
2. If I want to strip the category prefix, i.e. use a plugin like this:
<?php
/*
Plugin Name: Category Pagination Fix
Plugin URI: https://wordpress.stackexchange.com/a/311858/110572
Description: Fix category pagination
Version: 1.0.0
Author: Fayaz Ahmed
Author URI: https://www.fayazmiraz.com/
*/
function wpse311858_fix_category_pagination( $query_string = array() )
{
if( isset( $query_string['category_name'] )
&& isset( $query_string['name'] ) && $query_string['name'] === 'page'
&& isset( $query_string['page'] ) ) {
$paged = trim( $query_string['page'], '/' );
if( is_numeric( $paged ) ) {
// we are not allowing 'page' as a page or post slug
unset( $query_string['name'] );
unset( $query_string['page'] ) ;
// for a category archive, proper pagination query string is 'paged'
$query_string['paged'] = ( int ) $paged;
}
}
return $query_string;
}
add_filter( 'request', 'wpse311858_fix_category_pagination' );
a. In the abc.com/news, archive page, the canonical is still the original URL with category base: abc.com/category/news, but with correct self-canonical in page-2, page-3.: abc.com/cateogry/news/page/2
b. Then I try to edit the canonical URL in category TSF section. If I input the canonical URL to be abc.com/news. Then all canonical URLs in page-2. page-3 are all the same: abc.com/news, without correct self canonical.
As you said, I might use an archive template for displaying posts, but I also need to strip the category prefix as well.
Conclusion,
with category prefix, all fine.
without category prefix, the canonical has some conflicts.
What did I do wrong? Thanks!