Tagged: ,

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #605476

    Hi there,

    after trying to help myself, reading and coding a lot, I didn’t find the happy end, so I must ask:

    Please have a look at the current site (see private content)

    You see the language selector at the top left.

    I’d like to DON’T show the current (active) language, and I DON’T want flags to be shown, better not being loaded at all (and then hide them via css).

    I came across these:

    https://wpml.org/forums/topic/theme-enfold-delete-flag-header-menu/
    https://wpml.org/forums/topic/urgent-text-switcher-in-the-top-nav-bar-menu/

    I ended up with this in my child theme’s functions.php

    if(!function_exists('avia_wpml_language_switch'))
    	{
    		add_action( 'avia_meta_header', 'avia_wpml_language_switch', 10);
    		add_action( 'ava_main_header_sidebar', 'avia_wpml_language_switch', 10);
    
    		function avia_wpml_language_switch()
    		{
    			global $sitepress, $avia_config;
                
                if(empty($avia_config['wpml_language_menu_position'])) $avia_config['wpml_language_menu_position'] = apply_filters('avf_wpml_language_switcher_position', 'sub_menu');
                if($avia_config['wpml_language_menu_position'] != 'sub_menu') return;
    
    			$languages = icl_get_languages('skip_missing=0&orderby=custom');
    			$output = "";
    
    			if(is_array($languages))
    			{
    				$output .= "<ul class='avia_wpml_language_switch avia_wpml_language_switch_extra'>";
    
    				foreach($languages as $lang){
    				
    				if(!$lang['active'])
    				
    				{
    					$currentlang = (ICL_LANGUAGE_CODE == $lang['language_code']) ? 'avia_current_lang' : '';
    
    					if(!avia_is_overview() && (is_home() || is_front_page())) $lang['url'] = $sitepress->language_url($lang['language_code']);
    					         
    					$output .= "<li class='language_".$lang['language_code']." $currentlang'><a href='".$lang['url']."'>";
    					$output .= "	<span class='language_native'>".$lang['native_name']."</span>";
    					$output .= "</a></li>";
    				}
    
    				$output .= "</ul>";
    				}
    			}
    
    			echo $output;
    		}
    	}

    and I was near to what I wanted, but the styling was only working for the german language anymore.

    So please put me on the rails here. Thank you.

    #605760

    Hi cherrmann!

    Thank you for using Enfold.

    If you need to remove the current language in the switcher, add this in the Quick CSS field:

    .avia_current_lang {
        display: none !important;
    }

    Regards,
    Ismael

    #605898

    Thanks Ismael, while this is working (visually), I would like to put this a step further (as I wrote) and don’t load the flags and then hide them.

    #606476

    Hey!

    Alright. Please add this in the functions.php file:

    // remove current lang
    add_action( 'wp_footer', 'ava_custom_script' );
    function ava_custom_script() {
    	?>
    	<script type="text/javascript">
    	(function($){
    		function b() {
    			$('.avia_current_lang').remove();
    		}
    
    		b();
    	})(jQuery);
    	</script>
    	<?php
    }

    Best regards,
    Ismael

    #606638

    Hi Ismael,

    this is more what I like ;-) , I added one more line as:

    		function b() {
    			$('.avia_current_lang').remove();
    			$('.language_flag').remove();
    		}

    And this looks like the solution I was after. Please tell me if you underline it, or if there is any reason for not using the code like that.

    edit: seems that the flags still get loaded, and then get stripped of the code this way, right?

    My best regards.

    #606975

    Hi!

    Yes, the flag will be loaded then remove by the script. I don’t see any problem with that performance-wise. Actually, the css solution should be sufficient. I don’t seeany reason why you need to remove it completely.

    Regards,
    Ismael

    #607222

    Hi Ismael,

    I agree it’s not the best example to talk about performance here. Nevertheless I like ‘pretty’ solutions, and I like understanding what I’m doing. Why not cut the code where the flags are being loaded? If I could manage this, I know how to deal with other ‘problems’ like that. The code in the functions.php does work 99%, and I was behind the 1% which I oversaw..

    However:
    The jquery-solution now is not any better then using the CSS, right?

    What I will do next is trying again by myself.

    Thank you anyway, I appreciate what you’re doing, until now I bought your theme 3 times and made friends buying it. So something must be right about it ;-)

    #607246

    Got it, I think I just messed with the brackets or had some caching issue..

    So this is my final code, put in child theme’s functions.php.

    ...
    				$output .= "<ul class='avia_wpml_language_switch avia_wpml_language_switch_extra'>";
    
    				foreach($languages as $lang) {
    				
    				if(!$lang['active'])
    					
    					{
    						$currentlang = (ICL_LANGUAGE_CODE == $lang['language_code']) ? 'avia_current_lang' : '';
    
    						if(!avia_is_overview() && (is_home() || is_front_page())) $lang['url'] = $sitepress->language_url($lang['language_code']);
    								 
    						$output .= "<li class='language_".$lang['language_code']." $currentlang'><a href='".$lang['url']."'>";
    						$output .= "	<span class='language_native'>".$lang['native_name']."</span>";
    						$output .= "</a></li>";
    					}
    				}
    				$output .= "</ul>";
    			}
    
    			echo $output;
    
    ...
    

    And what a great performance dropping the flags !! :) :) :)

    Can be closed, thank you!

    #607396

    Hi!

    Glad you got it to work! Feel free to reach out to us again on the forum if you have any more questions.

    Best regards,
    Jordan

Viewing 9 posts - 1 through 9 (of 9 total)
  • The topic ‘WPML Language Menu without current language’ is closed to new replies.