Anwsering in case someone else might need it.
add_filter( 'the_seo_framework_rel_canonical_output', function( $url, $id ) {
if (is_paged()) {
$current_url="//".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
return $current_url;
}
return $url;
}, 10, 2 );
Hi Nikodemsky!
That filter defeats how TSF curates its canonical URL. I can now add random stuff to any of your paginated pages, post those links, and Google/Bing will index them. Less nefariously, your site might generate those links by accident. The moment you output a canonical URL, you “avouch” that the requested URL is “purposive.” So, it’d actually be better to disable the canonical URL so search engines can decide for themselves if a link is duplicated/intended.
Please note that TSF v4.2.0 had a regression where it didn’t correctly generate paginated URLs for categories — I resolved this in TSF v4.2.1 two weeks later. So, I recommend updating first.
If you already use TSF v4.2.1+, then it seems the pagination you implemented is not registered with WordPress, but only with the plugin generating it — Kadence Blocks is one offender that comes to mind.
Consider using WordPress’s native pagination, which will work with any theme, (SEO) plugin, block, etc.
Alternatively, I recommend using this filter:
add_filter( 'the_seo_framework_rel_canonical_output', function( $url, $id ) {
if ( is_paged() )
return '';
return $url;
}, 10, 2 );
I hope this helps! Cheers 🙂
I have tried above filter, but then source doesn’t show any canonical url at all for paginated pages :\
Hi Nikodemsky,
That’s the goal of it. It’s better to have no canonical URL than to have an exploitable one.
It’d be good to communicate this issue with the plugin/theme authors that implemented the pagination, as well.
I’m using WP-PageNavi – but i don’t think it modifies canonical urls.
The thing came from client’s SEO firm, i’m not questioning how it should be because i don’t really know :>
How should i approach it to make the whole thing less exploitable?