I almost found a solution:
I used a custom function to generate new canonical tags on paginated pages:
function wpseo_custom_rel_next_prev_canonical_links(){
global $paged;
if ( get_previous_posts_link() ) {
echo "<link rel='prev' href='".get_pagenum_link( $paged - 1 )."' />";
}
if ( get_next_posts_link() ) {
echo "<link rel='next' href='".get_pagenum_link( $paged +1 )."' />";
}
}
add_action( 'wp_head', 'wpseo_custom_rel_next_prev_canonical_links' );
It works on my search page which use search.php. But it return nothing on my home page which use a shortcode to insert “Search & Filter” results. I think get_previous_posts_link()
and get_next_posts_link()
return false or $paged
doesn’t exist on this page…