The Linux Page

Polylang messes up my canonical link on my website

UPDATE:

I reported this problem to the author who took a bit of time but ended up fixing the problem. If you still have a problem, you probably need to upgrade to the newest version.


I just created a new website and added a few plugins, one of which is Polylang. It generally works okay. Not what I really would like to have, but close enough for a Wordpress website.

Only, it has a horrible side effect:

I destroys the canonical URL which instead of appearing as expected appears with a "%pagename%" variable in it. This is because the module caches the results of a previous call and returns that cahed value instead of recomputing it. There isn't really a way for the filter at that low level to know what version should be returned, so it ends up returning the wrong one.

To fix the problem, I went to the plugin and commented out two lines.

In the file named wp-content/plugins/polylang/include/filters-links.php

Search for a couple of lines that start with "add_filter(". In the offensive version, the original code looks like this:

if ( $this->options['force_lang'] ) {
        add_filter( 'post_link', array( $this, 'post_type_link' ), 20, 2 );
        add_filter( '_get_page_link', array( $this, '_get_page_link' ), 20, 2 );
}

Once ommented out, it looks like this:

if ( $this->options['force_lang'] ) {
        //add_filter( 'post_link', array( $this, 'post_type_link' ), 20, 2 );
        //add_filter( '_get_page_link', array( $this, '_get_page_link' ), 20, 2 );
}

This obviously means the links cannot all be working quite right. But at least my canonical is showing up as expected now.

My Bug Report https://github.com/polylang/polylang/issues/149

Syndicate content

SMS From Me Logo

SMS From Me

To automatically start one on one conversations with your online leads.

     

   

Terms of Site Index

Find the page/content you are looking for with our index.

  • Apache
    Apache is the most well known Open Source Web Server.
  • MS-DOS
  • font
  • footer

    The bottom of a page, generally something that appears on all the pages such as the current page number, total number of pages, date when it was printed, and the name of the company.

  • logo

    The term logo usually references a small image or icon used to represent a business or product. In computing, there is also the LOGO language, a simplified version of the lisp language, if I may.