Post by p206ab » Wed Feb 25, 2015 4:00 pm

Hello,

does anyone know how to set up hreflang tags for multilanguage opencart site?
Because in hreflang tag you have to insert an URL to point users to a certain language, but opencart changes languages using script by default, like the one below.

Code: Select all

<img src="image/flags/gb.png" alt="English" title="English" onclick="$('input[name=\'language_code\']').attr('value', 'en').submit(); $(this).parent().parent().submit();">
So what do I insert into hreflang tag? Is it possible to change script above, so languages change via simple URL?

Thanks in advance! ;)

Newbie

Posts

Joined
Tue Feb 25, 2014 8:13 pm

Post by IP_CAM » Thu Feb 26, 2015 10:22 am

Try this here, I tested it, it most of the times works on my v.1.5.6.4+:

http://perfectcod.es/2013/07/05/opencar ... rough-url/

Ernie
bigmax.ch/shop/

----- Start taken from the Site!

Although the built-in language selection in OpenCart close to perfect, If you need a language switcher extension for any text anywhere on the site, here are simple code to create links that direct users to the store in a specific language.

This code may use http referer as redirect URL, so it’s no redirect URL need.

Open file in
catalog/controller/module/language.php
Add this code before line 4:

Code: Select all

    	if (isset($this->request->get['lang'])) {

			$this->session->data['language'] = $this->request->get['lang'];

			if (isset($_SERVER['HTTP_REFERER']) && (strpos($_SERVER['HTTP_REFERER'], $this->config->get('config_url')) !== false) ) {

				$this->redirect($_SERVER['HTTP_REFERER']);

			} else {

				$this->redirect($this->url->link('common/home'));

			}

    	} else
So, that the 'Modded Section will look like this Finished/Combined Example, starting from Line 1:

Code: Select all

<?php
   class ControllerModuleLanguage extends Controller {
  	protected function index() {
     	 		if (isset($this->request->get['lang'])) {

			$this->session->data['language'] = $this->request->get['lang'];

			if (isset($_SERVER['HTTP_REFERER']) && (strpos($_SERVER['HTTP_REFERER'], $this->config->get('config_url')) !== false) ) {

				$this->redirect($_SERVER['HTTP_REFERER']);

			} else {

				$this->redirect($this->url->link('common/home'));

			}

    	} elseif (isset($this->request->post['language_code'])) {
			$this->session->data['language'] = $this->request->post['language_code'];

			if (isset($this->request->post['redirect'])) {
				$this->redirect($this->request->post['redirect']);
			} else {
				$this->redirect($this->url->link('common/home'));
			}
    	}
----- END taken from the Site!

BE AWARE, that you have JUST created an ELSEIF ... out of your ELSE - end of Mod, like:
from:
} else
to:
} elseif .......
[/b]

----- taken from the Site!
Now you may test your language in URL. If you have English and Spanish on your site and you would use:
http://yourstore.com/?lang=en (for English) or
http://yourstore.com/?lang=es (for Spanish)[/code]
----- END taken from the Site!

http://forum.opencart.com/viewtopic.php?f=24&t=13273
http://forum.opencart.com/viewtopic.php?f=20&t=69231

GOOGLE FOR: "language in URL Opencart"

My Github OC Site: https://github.com/IP-CAM
5'600 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by p206ab » Fri Feb 27, 2015 3:24 pm

Awesome, will try this, thank you very much!

Newbie

Posts

Joined
Tue Feb 25, 2014 8:13 pm
Who is online

Users browsing this forum: No registered users and 49 guests