Skip Navigation

Waiting for author

Topic Tags: Compatibility

Overview of the issue

When using SEOPress with WPML, canonical URLs for untranslated content do not point to the default language when the “Default language as a fallback” or “Duplicating content” methods are used. This can lead to duplicate content issues.

Workaround

Please, make sure of having a full site backup of your site before proceeding.

  • Open: …/wp-content/plugins/wp-seopress/inc/functions/options-titles-metas.php
  • Look for line 1022
  • Replace:
            function seopress_titles_canonical_hook() {
                global $wp;
    
                $current_url = user_trailingslashit(home_url(add_query_arg([], $wp->request)));
    
                if (is_search()) {
                    $seopress_titles_canonical = '';
                } elseif (is_paged() && is_singular()) {//Paginated pages
                    $seopress_titles_canonical = '';
                } elseif (is_paged()) {
                    $seopress_titles_canonical = '';
                } elseif (is_singular()) {
                    $seopress_titles_canonical = '';
                } else {
                    $seopress_titles_canonical = '';
                }
                //Hook on post canonical URL - 'seopress_titles_canonical'
                if (has_filter('seopress_titles_canonical')) {
                    $seopress_titles_canonical = apply_filters('seopress_titles_canonical', $seopress_titles_canonical);
                }
                echo $seopress_titles_canonical . "n";
            }
    
  • With:
            function seopress_titles_canonical_hook() {
                global $wp;
    
                $current_url = user_trailingslashit(home_url(add_query_arg([], $wp->request)));
                // WPML Workaround for compsupp-7703
                if (class_exists('SitePress')) {
                  $post_ID = get_the_ID();
                  $post_type = get_post_type( $post_ID );
                  $transl_status = apply_filters( 'wpml_element_translation_type', NULL, $post_ID, $post_type );
                  // If the post is not translated, switch to the default language
                  if ($transl_status != 1) { 
                      $my_default_lang = apply_filters('wpml_default_language', NULL );
                      $my_current_lang = apply_filters( 'wpml_current_language', NULL );
                      do_action( 'wpml_switch_language', $my_default_lang );
                  } 
                }
                if (is_search()) {
                    $seopress_titles_canonical = '';
                } elseif (is_paged() && is_singular()) {//Paginated pages
                    $seopress_titles_canonical = '';
                } elseif (is_paged()) {
                    $seopress_titles_canonical = '';
                } elseif (is_singular()) {
                    $seopress_titles_canonical = '';
                } else {
                    $seopress_titles_canonical = '';
                }
                // Then switch back to the current language
                if (class_exists('SitePress')) {
                  do_action( 'wpml_switch_language', $my_current_lang );
                }
                //Hook on post canonical URL - 'seopress_titles_canonical'
                if (has_filter('seopress_titles_canonical')) {
                    $seopress_titles_canonical = apply_filters('seopress_titles_canonical', $seopress_titles_canonical);
                }
                echo $seopress_titles_canonical . "n";
            }
    

Leave a Reply

Please stay on topic and be respectful to others. If you need help with issues not related to this post, use our Support Forum to start a chat or submit a ticket.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>