
<?php 
	$have_wpml = function_exists( 'icl_get_languages' );
?>


<!-- Language dropdown -->
<?php
if ($have_wpml) {
	$languages = icl_get_languages('skip_missing=1');
	if ( !empty($languages)) : ?>
		<div class="select-small lang-dropdown">
			<div class="select select-dropdown">
				<div class="select-styled">
					<?php
					// $languages = icl_get_languages('skip_missing=1');
					$curr_lang = array();
					if ( !empty( $languages ) ) {
						foreach( $languages as $language ) {
							if( !empty( $language['active'] ) ) {
								$curr_lang = $language; // This will contain current language info.
								break;
							}
						}
						echo '<img src="' . $curr_lang['country_flag_url'] . '" alt="'.$curr_lang['code'].'" class="icon">';
						echo esc_html( $curr_lang['translated_name'] );
					}
					?>
				</div>
				<ul class="select-options">
					<?php
					$languages = icl_get_languages('orderby=name');
					foreach( $languages as $language ) {
						$class = ( $language['active'] ) ? ' class="active"' : '';
						printf( '<li%s><a href="%s"><img src="%s" alt="%s">%s</a></li>', $class, $language['url'],
						$language['country_flag_url'], $language['code'], $language['native_name'] );
					}
					?>
				</ul>
			</div>
		</div>
	<?php endif; ?>
<?php } ?>