Language Switching Button – Other Language only
-
I searched far and wide for a easy way to create a language switching button / link to the language not being currently used. After finding some sample ways to do it I came up with this. Hope this helps someone.
Essentially this will create a link to the alternate language on any page and allow you to limit the anchor text to show as many letters as you like for a language.
function my_qtranxf_generateLanguageSelectCode($style='', $id='', $lettersToKeep=3) { ob_start(); qtranxf_generateLanguageSelectCode($style, $id); $o = ob_get_contents(); ob_end_clean(); $dom = new DOMDocument(); $dom->loadHTML($o); $nodes = $dom->getElementsByTagName("a"); $link = "<a"; foreach($nodes as $searchNodes){ if(qtrans_getLanguage() != $searchNodes->getAttribute("hreflang")){ $link .= " href='" . $searchNodes->getAttribute("href") . "'"; $link .= " hreflang='" . $searchNodes->getAttribute("hreflang") . "'"; $link .= " title='" . $searchNodes->getAttribute("title") . "'"; $link .= " class='" . $searchNodes->getAttribute("class") . "'"; $link .= " >"; $link .= substr($searchNodes->nodeValue, 0, $lettersToKeep); } } $link .= "</a>"; return $link; }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Language Switching Button – Other Language only’ is closed to new replies.