• Resolved Nikodemsky

    (@nikodemsky)


    Hi, i have a bit of a problem with canonical urls with paged pages for archives etc.

    For example:
    mywww.com/news/page/2/
    shows canonical for parent page which is:
    mywww.com/news/
    – but i need it to actually show canonical for that page(which is mywww.com/news/page/2/)

    How can i achive that?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Nikodemsky

    (@nikodemsky)

    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 );
    Plugin Author Sybre Waaijer

    (@cybr)

    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 ??

    Thread Starter Nikodemsky

    (@nikodemsky)

    I have tried above filter, but then source doesn’t show any canonical url at all for paginated pages :\

    Plugin Author Sybre Waaijer

    (@cybr)

    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.

    Thread Starter Nikodemsky

    (@nikodemsky)

    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?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Canonical url for paged?’ is closed to new replies.