Support » Plugin: qTranslate » qtranslate flags in header

  • Hi i have install qtranslate and from this post i manage to add the language links to my header but i can manage to add flags img to the links .
    This is my site here :

    So i add to header.php this code :

      global $q_config;
      if(is_404()) $url = get_option('home'); else $url = '';
      echo '<ul id="headerMenuSystem">';
      foreach(qtrans_getSortedLanguages() as $language)
        $link = qtrans_convertURL('', $language);
        if($_SERVER["HTTPS"] == "on")
          $link = preg_replace('#^http://#','https://', $link);
        echo '<li class="menu_item"><a href="'.$link.'"';
        echo ' hreflang="'.$language.'" title="'.$q_config['language_name'][$language].'"';
        echo '><span';
        echo '>'.$q_config['language_name'][$language].'</span></a></li>';
      echo '</ul>';

    and it the custom css i add this:

    #headerMenuSystem { list-style: none; }
    #headerMenuSystem li { float:right; width:auto; padding:0 20px 0 0; }

    In that post “kvspublic” said to

    add “img” tag before “span”

    . but i do not know where to add this ,so can anyone help me with this?


    How can i invert the order of the languages ? “English” to left and “Romana” to right

    Thank you all

    [No bumping. If it’s that urgent, consider hiring someone.]

Viewing 9 replies - 1 through 9 (of 9 total)
  • I use the small function below to create a div with only the language flags. You might be able to adapt it to your needs:

    // Language Select Code for non-Widget users
    function mwo_qtrans_language_flags_menu() {
    	if ( !function_exists( "qtrans_getSortedLanguages" ) ) {
    		// plugin qTranslate must be active
    		echo '<!-- Please activate the qTranslate plugin -->';
    	global $q_config;
    	if( is_404() ) {
    		$url = get_option( 'home' );
    	} else {
    		$url = '';
    	$languages = qtrans_getSortedLanguages( true );
    	foreach($languages as $language) {
    		$classes = array( 'language', 'lang-'.$language );
    		// add an extra style class to the active language
    		if( $language == $q_config[ 'language' ] ) {
    			$classes[] = 'active';
    		echo '<div class="'. implode(' ', $classes) .'"><a href="'.qtrans_convertURL( $url, $language ).'"';
    		echo ' hreflang="' . $language . '" title="' . $q_config[ 'language_name' ][ $language ] . '">';
    		echo '<img src="' . get_stylesheet_directory_uri() . '/images/flags/' . $language . '.png" alt="' . $q_config[ 'language_name' ][ $language ] . '" /></a></div>' . "\n";

    benisv, I see you didn’t succeed to put pics on your language links.
    sanderbontje, I tried to use your code, but it shows on the page, after saving.
    Is there something you will suggest to add/remove in it, please?
    Thank you!

    What shows on the page? The code? Did you put it inside PHP tags? Please be more specific when you ask for help.

    sanderbontje, you actually gave me the answer 🙂
    I didn’t put the php tags. I just blindly copy/pasted the code.
    Now I;ll try it agin and I’ll give you a feedback.

    Nothing happened.I mean It didn’t show flags on the page.
    Thank you for your time anyway 🙂

    That snippet of code outputs img tags, the src is pointing to an subfolder of your theme. So you have to make sure that those images exist. For example <your-theme-dir>/images/flags/nl.png for Dutch. Adapt the code to fit your own theme design.

    When you look at the generated HTML source of your page, can you see the img tags being printed?

    Dear sanderbontje,
    I’m thrilled by your help! It’s no easy to teach others and be tolerant!

    I made it 🙂

    heres what I found and works perfect:

    In header.php added
    echo “<div style=’position:relative; margin-left:200px; padding-top:15px;’>”;
    echo qtrans_generateLanguageSelectCode(‘both’);
    echo “</div>”;

    Then in the Quick CSS added:
    .qtrans_language_chooser li { float: left; position: relative; display: inline; padding-right: 6px; padding-top:3px; }
    a.qtrans_flag:hover {background-position: -18px 0 ; }

    Thank you for your time 🙂

    No problem, glad it worked out!

    Thanks for the help!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘qtranslate flags in header’ is closed to new replies.