Hello, we apologize for the inconvenience you are facing with Rank Math and Polylang compatibility. Currently, Polylang doesn’t have native compatibility with Rank Math, and there are no plans from Polylang’s end to integrate it. However, you can manually resolve these compatibility issues by adding specific code to your website.
To address the canonical URL issue for your Homepage, you can follow the steps outlined in our knowledgebase article on how to make Polylang compatible with Rank Math. By adding the necessary code to your theme files, you can ensure better integration between Rank Math and Polylang.
If you encounter any difficulties or have further questions during this process, please feel free to reach out to our dedicated support team here. We are available 24/7 to assist you. Thank you for raising this concern, and we appreciate your understanding.
Sources:
How to Make Polylang Compatible With Rank Math
Multilingual SEO with Rank Math SEO & WPML » Rank Math
The #1 WordPress SEO Plugin in 2023 – Rank Math
Using an AMP Plugin with Rank Math SEO » Rank Math
YoastSEO:
if ( defined( 'WPSEO_VERSION' ) ) {
add_action( 'pll_init', array( $this->wpseo = new PLL_WPSEO(), 'init' ) );
}
Rank Math:
if ( defined( 'RANK_MATH_VERSION' ) ) {
include PLL_MODULES_INC . '/plugins/rank-math.php';
add_action( 'pll_language_defined', array( $this->rank_math = new PLL_RankMath(), 'init' ) );
}
Why add the rank-math.php in the polylang plugin? Shouldn’t that be handled by Rank Math? I bet if you remove that file and just add the plugin files in your plugin, Polylang will be happy to add that code snippet
I definietly also wouldn’t be happy having to maintain a 3rd party plugin file
Also SeoKey does it without a MR
Addition:
https://rankmath.com/kb/polylang-compatibility/
Doesn’t work properly for canonical URLs
/**
* Include language code in the canonical URL.
*
* @param string $canonical The canonical URL.
*
* @return mixed|string
*/
public function rm_home_canonical( $canonical ) {
if ( ! is_home() ) {
return $canonical;
}
$path = ltrim( (string) wp_parse_url( pll_get_requested_url(), PHP_URL_PATH ), '/' );
return $canonical . $path;
}
needs to be:
/**
* Include language code in the canonical URL.
*
* @param string $canonical The canonical URL.
*
* @return mixed|string
*/
public function rm_home_canonical( $canonical ) {
$path = ltrim( (string) wp_parse_url( pll_get_requested_url(), PHP_URL_PATH ), '/' );
return $canonical . $path;
}
because is_home() always returns false on wordpress multisites
Also it’s better to add it as plugin (which i did) it seems to work properly then
Hello,
I just tested the code from the kb article on a multi-site and the canonical URL behaves as expected.
See this screen cast
Could you include admin access details in the sensitive data area so we may take a look at why this is happening on your site.
We look forward to having this issue resolved.
Thank you
Hello,
Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.
If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.
Thank you.