Resolved by author
Reported for: WPML SEO 2.0.1
Overview of the issue
This is a general problem with Yoast SEO (not specific to WPML) and it has been reported here.
If you are formatting your URLs to display language as a parameter in WPML → Languages, you will notice that pages in secondary languages that are paginated will display an incorrect canonical link.
Workaround
Please, make a full backup of your site before proceeding. Then, add the following code in your functions.php theme file:
// define the wpseo_canonical callback function wpmldp_filter_wpseo_canonical_lang_parameter_position( $canonical ) { // decode URL $canonical = urldecode($canonical); // get current language $my_current_lang = apply_filters( 'wpml_current_language', NULL ); // define ?lang parameter $param = '?lang='.$my_current_lang; // check if current $canonical contains the parameter if(strpos($canonical, $param) !== false){ // remove the parameter from URL $canonical = str_replace('/'.$param, "", $canonical); // add it again $canonical = $canonical.$param; } return $canonical; }; // add the filter add_filter( 'wpseo_canonical', 'wpmldp_filter_wpseo_canonical_lang_parameter_position', 999 );
Hi,
I have encountered this problem discovered when analysing the head tag
N’est pas une URL absolue (https%3A%2F%2Fscience-sense.com%2F)
Finally I corrected the problem by dis-activating your plugin part of the wpml bundle.
I tried your code (activated) in the functions file and cleared the site and navigator cache but the problem persisted.
Please tell me what to do next so that I can use this paid version of wpml SEO
Regards
Hello there,
According to your description, your problem is not the same here described. Could you please open a chat in our support forum so we can investigate it?
Regards
Hi,
I’ve added this code and it seemed to work but now I get the following fatal error:
Fatal error: Uncaught Error: call_user_func_array(): Argument #1 ($callback) must be a valid callback, function “wpmldp_filter_wpseo_canonical_lang_parameter_position” not found or invalid function name
in /home/xxx.cloudwaysapps.com/nvvxjzdyea/public_html/wp-includes/class-wp-hook.php on line 310
Oproepstack:
WP_Hook::apply_filters()
wp-includes/plugin.php:205
apply_filters()
wp-content/plugins/wordpress-seo/src/presenters/canonical-presenter.php:50
Yoast\W\S\P\Canonical_Presenter::get()
wp-content/plugins/wordpress-seo/src/presenters/abstract-indexable-tag-presenter.php:37
Yoast\W\S\P\Abstract_Indexable_Tag_Presenter::present()
wp-content/plugins/wordpress-seo/src/integrations/front-end-integration.php:326
Yoast\W\S\I\Front_End_Integration::present_head()
wp-includes/class-wp-hook.php:308
WP_Hook::apply_filters()
wp-includes/class-wp-hook.php:332
WP_Hook::do_action()
wp-includes/plugin.php:517
do_action()
wp-content/plugins/wordpress-seo/src/integrations/front-end-integration.php:300
Yoast\W\S\I\Front_End_Integration::call_wpseo_head()
wp-includes/class-wp-hook.php:308
WP_Hook::apply_filters()
wp-includes/class-wp-hook.php:332
WP_Hook::do_action()
wp-includes/plugin.php:517
do_action()
wp-includes/general-template.php:3043
wp_head()
wp-content/themes/flatsome/header.php:17
require_once()
wp-includes/template.php:783
load_template()
wp-includes/template.php:718
locate_template()
wp-includes/general-template.php:48
get_header()
wp-content/themes/flatsome/page-blank.php:9
include()
wp-includes/template-loader.php:106
require_once()
wp-blog-header.php:19
require()
index.php:17
Is there another way to temporarily fix this issue?
Cheers,
Jaap
Hello Jaap,
I’ve updated this page as the workaround lost its format and there could have an issue. Could you please give it another try?
If it still does not work, please open a chat in our support forum and share your findings.
We will investigate it further.
Regards
Thanks for the workaround and explanation! Workaround works on my end. (Yoast SEO version 20).
Thanks for the update, Caroline. We are glad it worked!
We will keep this link updated.
How about if pagination is with query strings in the format of /?page=2
then what should we do if we want yoast seo to generate correct urls in canonical and rel next prev seo tags?
Hey there,
This issue was related to Yoast plugin and not WPML. It should have been solved with Yoast SEO 20.3 version. I recommend you to contact their support for further information or if you are still experiencing this issue.
Regards