Adding language selection to the code ? (WPML plugin )


	<?php

	function language_selector_flags(){
                // get array from this function
		$languages = icl_get_languages('skip_missing=0&orderby=code');
		if(!empty($languages)){
			foreach($languages as $l){
				if(!$l['active']) echo '<a href="'.$l['url'].'">';
				echo '<img src="'.$l['country_flag_url'].'" height="12" alt="'.$l['language_code'].'" width="18" />';
				echo icl_disp_language($l['native_name'], $l['translated_name']); //DISPLAY LANGUAGE NAME

				if(!$l['active']) echo '</a>';
			}
		}
	}

	?>
	<div id="flags_language_selector"><?php language_selector_flags(); ?></div >

You may have to add some css make it look better like the following :


#flags_language_selector {

 float: right;
 padding:0 5px;

}

#flags_language_selector img{
 margin:1px;
 border:1px solid #333;

}

For more information check the following link :
http://wpml.org/documentation/getting-started-guide/language-setup/custom-language-switcher/

Advertisements
Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: