• 5 Subscribers
  • 114 Views
0

I use Opencart ecommerce package for my webshop which is available in 3 languages (Dutch, English and French). Last year I have bought a complete SEO package module to improve SEO performance. On of the features is that this module installs hreflang tags for all my pages. But Google webmaster displays warnings about the missing of the appropriate hreflang tags for several pages: 47 pages with warning " 'en' - no return tags" and 44 pages with warning " 'fr' - no return tags. The autor of the SEO module has disappeared and does not provide any support at all anymore!

I want to check if I could avoid these Google warnings and modify the code to get correct hreflang tags for all pages.

See below the links the module creates for a typical the product pages which is available in 3 languages (dutch, english and French) and wich generates a warning. Please be aware that I have choosen not to implement /nl or /en or /fr in my SEO url's. Each SEO url is unique because of the different translations for categoryname, productname and model name.

The English page:

<link hreflang="nl" href="https://www.example.com/categorie/onder_categorie/prod6403-merknaam-model" rel="alternate" type="text/html" />
<link hreflang="fr" href="https://www.example.com/catégorie/sous-catégorie/prod6403-marque-nom_produit-modèle" rel="alternate" type="text/html" /> 
<link hreflang="en" href="https://www.example.com/category/subcategory/prod6403-brand-productname-model" rel="alternate" type="text/html" />
<link href="http://example.com/categorie/onder_categorie/prod6403-merknaam-model" rel="canonical" />

The French page:

<link hreflang="nl" href="https://www.example.com/categorie/onder_categorie/prod6403-merknaam-model" rel="alternate" type="text/html" />
<link hreflang="fr" href="https://www.example.com/catégorie/sous-catégorie/prod6403-marque-nom_produit-modèle" rel="alternate" type="text/html" /> 
<link hreflang="en" href="https://www.example.com/category/subcategory/prod6403-brand-productname-model" rel="alternate" type="text/html" />
<link href="http://example.com/catégorie/sous-catégorie/prod6403-marque-nom_produit-modèle" rel="canonical" />

The Dutch page (default language in backend):

<link hreflang="fr" href="https://www.example.com/catégorie/sous-catégorie/prod6403-marque-nom_produit-modèle" rel="alternate" type="text/html" /> 
<link hreflang="en" href="https://www.example.com/category/subcategory/prod6403-brand-productname-model" rel="alternate" type="text/html" />
<link href="http://example.com/categorie/onder_categorie/prod6403-merknaam-model" rel="canonical" />

I think there are 2 errors in the way the hreflang links are created and wich causes a warning from google:

  1. In the dutch page, the link for the nl variant is missing
  2. My site is completely in https and is redirected to include www, so I think all canonical links should have https://www.example.com instead of http://example.com and this is a serious error in SEO ranking?
  3. The rest of the links seems OK to me?

What is your opinion about this?

The code for hreflang is generated in this php page where hreflang is appearing (sorry, some of the code is written in condensed mode):

<?php class seoController extends Controller { function __construct(){ global $registry;parent::__construct($registry);require_once DIR_CONFIG.'ssb_library/ssb_helper.php';$this->ssb_helper=ssb_helper::getInstance();require_once DIR_CONFIG.'ssb_library/catalog/tools/path_controller.php';$this->pathController=pathController::getInstance();require_once DIR_CONFIG.'ssb_library/ssb_data.php';$this->ssb_data=ssb_data::getInstance();$this->ssb_setting=$this->ssb_data->getSetting();$this->totalLanguages=isset($_SESSION['totalLanguages']) ? $_SESSION['totalLanguages']:$this->ssb_helper->getActiveLang();$this->def_lang_code=isset($_SESSION['def_lang_code']) ? $_SESSION['def_lang_code']:$this->ssb_helper->getDefaultLanguage();} static private $Instance =NULL;static public function getInstance() { if(self::$Instance==NULL){ $class=__CLASS__;self::$Instance=new $class;} return self::$Instance;} public function getDefaultLanguageData(){ return array($this->totalLanguages,$this->def_lang_code);} public function setLanguageData(){ if(isset($this->session->data['language'])){ $this->l_code_session=$this->session->data['language'];$this->config->set('config_language',$this->l_code_session);}elseif(isset($_SESSION['language'])){ $this->l_code_session=$this->session->data['language']=$_SESSION['language'];$this->config->set('config_language',$this->l_code_session);}else{ $this->l_code_session=$this->config->get('config_language');} $this->l_id_session=$this->ssb_helper->getLang_Code_Id($this->l_code_session);return array($this->l_code_session,$this->l_id_session);} public function curPageURL() { $s=$_SERVER;$use_forwarded_host=false;$ssl =( ! empty( $s['HTTPS'] ) && $s['HTTPS']=='on' );$sp =strtolower( $s['SERVER_PROTOCOL'] );$protocol=substr( $sp,0,strpos( $sp,'/' ) ).( ( $ssl ) ? 's':'' );$port =$s['SERVER_PORT'];$port =( ( ! $ssl && $port=='80' ) || ( $ssl && $port=='443' ) ) ? '':':'.$port;$host =( $use_forwarded_host && isset( $s['HTTP_X_FORWARDED_HOST'] ) ) ? $s['HTTP_X_FORWARDED_HOST']:( isset( $s['HTTP_HOST'] ) ? $s['HTTP_HOST']:null );$host =isset( $host ) ? $host:$s['SERVER_NAME'].$port;return $protocol.'://'.$host.$_SERVER['REQUEST_URI'];} private function actionCheckURL($mode){ switch ($mode) { case 'redirect':$this->redirectPermanently();break;case 'page404':$this->request->get['route']='error/not_found';break;} } public function redirectPermanently(){ $query_url=$this->request->get;unset($query_url['route']);unset($query_url['_route_']);$query_url =http_build_query($query_url);$route =isset($this->request->get['route']) ? $this->request->get['route']:'common/home';$new_url=$this->url->link($route,$query_url,'SSL');$this->ssb_helper->redirect($new_url,301);} public function alternetHref(){ $query_url=$this->request->get;unset($query_url['route']);unset($query_url['_route_']);$alternet_route=isset($this->request->get['route']) ? $this->request->get['route']:'common/home';if($this->totalLanguages > 1 AND $this->ssb_setting['tools']['href_lang']['status']){ $arrayLangCode=array();$arrayLangCode=$this->ssb_helper->getArrayLangCode();$current_l_code_session=$this->l_code_session;foreach($arrayLangCode as $l_code){ if($this->l_code_session==$l_code)continue;$this->session->data['language']=$l_code;$href=$this->url->link($alternet_route,http_build_query($query_url),'SSL');$this->document->addCustomLink($href,'alternate',array(array('hreflang'=> $l_code)),'text/html');} $this->session->data['language']=$current_l_code_session;$this->setLanguageData();} } public function errorNotFound() { if(isset($this->request->get['route']) AND $this->request->get['route']=='error/not_found'){ require_once DIR_CONFIG.'ssb_library/ssb_custom_404.php';$this->ssb_custom_404=ssb_custom_404::getInstance();$url_404=$this->ssb_custom_404->getUrl404(array('url_404'=> $this->curPageURL));if($url_404){ $this->ssb_custom_404->addHit($url_404['custom_url_404_id']);if($url_404['url_redirect']){ $this->ssb_helper->redirect($url_404['url_redirect'],301);} }else{ $this->ssb_custom_404->insertUrl(array('url_404'=> $this->curPageURL));} } }  public function startPathManager($data){
$page_type='';
$path_mode='default';
if(isset($data['route']) && $data['route']=='product/product' && isset($data['product_id'])){ 
    $path_mode=$this->ssb_setting['tools']['path_manager']['data']['product']['mode'];
    $page_type='product';
    $product_id=$data['product_id'];
}else if(isset($data['path'])){
    $path_mode=$this->ssb_setting['tools']['path_manager']['data']['category']['mode'];
    $page_type='category';
} 
$this->path_mode=$path_mode;
if($path_mode=='direct'){ 
    switch ($page_type) { 
        case 'product':
            unset($data['path']);
            break;
        case 'category':
            $categories=explode('_',$data['path']);
            $category_id=$categories[count($categories)-1];
            if(isset($data['path'])){
                $data['path']=$category_id;
            }else{ 
                $data=array('path'=> $category_id)+$data;
            } 
            break;
    }
}else if($path_mode !='default'){
    switch ($page_type) {
        case 'product':
            $new_path=$this->pathController->getProductPath($product_id,$path_mode);
            if(count($new_path)){
                if(isset($data['path'])){
                    $data['path']=$new_path[count($new_path)-1]['path'];
                }else{
                    $data=array('path'=> $new_path[count($new_path)-1]['path'])+$data;
                }
            }
            break;
        case 'category':
            $categories=explode('_',$data['path']);
            $category_id=$categories[count($categories)-1];
            $new_path=$this->pathController->getCaregoryPath($category_id,$path_mode);
            if(isset($data['path'])){
                $data['path']=$new_path[count($new_path)-1]['path'];
            }else{
                $data=array('path'=> $new_path[count($new_path)-1]['path'])+$data;
            }
            break;
        }
    } 
    return array($data,$path_mode);
} 
public function getHost($url_info) { if (strpos('a'.$url_info['scheme'].'a','https') !==false ) { $host=$this->config->get('config_ssl');} else { $host=$this->config->get('config_url');} return trim($host,'/');} public function getPath($l_code,$host,$url_info){ $l_code=$l_code==$this->def_lang_code ? '':$l_code;$path=$l_code;if (isset($url_info['path']) ) { $host_array=explode('/',$host);$path_array=explode('/',$url_info['path']);foreach ($path_array as $key=> $path_part) { if(!empty($path_part)){ if (in_array($path_part,$host_array)) unset($path_array[$key]);} } $path.=implode('/',$path_array);$path=str_replace('/index.php','',$path);$path=trim($path,'/');} $path=$path ? '/'.$path:'';return $path;} public function getPagePart($url_info){ $page_part='';$setting=$this->ssb_setting;$tools=$setting['tools'];if($tools['seo_pagination']['status']){ $query='';$page='';if(isset($url_info['query'])){ $parts=explode('&',$url_info['query']);foreach($parts as $part){ if(strpos($part,'page') !==false){ $page=preg_replace("/[^0-9]/",'',$part);} } $query='?'.preg_replace("/&*page=[0-9]/i","",$url_info['query']);} if($page !=''){ $setting =$this->ssb_setting;$CPBI_urls_ext=$setting['entity']['urls']['CPBI_urls']['ext'];$STAN_urls_ext=$setting['entity']['urls']['STAN_urls']['ext'];$url_info['path']=preg_replace("/\/page-[0-9]+".$STAN_urls_ext."/i","",$url_info['path']);$url_info['path']=preg_replace("/".$CPBI_urls_ext."$/i","",$url_info['path']);$page_part='/page-'.$page.$STAN_urls_ext;} } return array($page_part,$url_info);} public function checkPathController($no_exist_one_of_url_part) { if($this->ssb_setting['tools']['check_url']['status']){ $check_mode_wrong_url=$this->ssb_setting['tools']['check_url']['data']['mode']['wrong_url'];$check_mode_wrong_path=$this->ssb_setting['tools']['check_url']['data']['mode']['wrong_path'];$standard_route=array('product/product','product/category','product/manufacturer/info','information/information');if(isset($this->request->get['route']) AND in_array($this->request->get['route'],$standard_route) AND $no_exist_one_of_url_part){ $this->actionCheckURL($check_mode_wrong_url);} if (isset($this->request->get['product_id'])) { $path_mode=$this->ssb_setting['tools']['path_manager']['data']['product']['mode'];if($path_mode !='default'){ $current_path=isset($this->request->get['path']) ? $this->request->get['path']:'';$need_path=$this->pathController->getRealProductPath($this->request->get['product_id'],$path_mode);if($need_path !=$current_path){ $this->actionCheckURL($check_mode_wrong_path);} } } elseif (isset($this->request->get['path'])) { $path_mode=$this->ssb_setting['tools']['path_manager']['data']['category']['mode'];if($path_mode !='default'){ $current_path=$this->request->get['path'];$category_array=explode('_',$current_path);$category_id=end($category_array );$need_path=$this->pathController->getRealCaregoryPath($category_id,$path_mode);if($need_path !=$current_path){ $this->actionCheckURL($check_mode_wrong_path);} } } } } } ?>

Is there somebody able to change this code in order to improve my hreflang links or give me some hints. Any help would be appreciated. I suppose that the link for the dutch page is wrong because dutch is selected as my default language in my backend and frontend?

Regards, SabKo


0 answers in total

Answer this questsion