Skip Navigation

[Resolved] Language Switcher to link to Post and not Home Language

This support ticket is created 5 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 replies, has 2 voices.

Last updated by Christian Cox 5 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#1239528

Hello,

I have created a View with a Content Template. I am using Visual Composure to design the layout and all is working pretty well. I am using the View for a job listing. The Job listing is in 4 Languages and so my end goal is you see the Job Title, an excerpt of the Job description. Then underneath this is the option to view the Job Description in the other languages.

I have been able to add the Language Switcher, but I notice when I click the Language I want to read the post in, I am only taken to the Home page of that language.

How can I click the Flag and I am taken to the full page of the listing from that language?

Site is in development so credentials to login:

vianova
via2019

hidden link

Scroll down to Join Us

For example, if you click NOW HIRING: ACCOUNTANT language for French, it should take you here: hidden link

How can I create an option that could do this?

Thank you for your time.

#1239539

Hi, there's nothing exactly like this built in to Toolset or WPML, because the Language Switcher is designed for use on single posts and not search results. Based on the code sample in the Custom Language Switcher documentation, I can provide you a custom shortcode that will do something similar. Here's the documentation link:
https://wpml.org/documentation/getting-started-guide/language-setup/custom-language-switcher/#language-selector-with-flags-only

Here's the code you can add to your child theme's functions.php file, or to a new Code Snippet in Toolset > Settings > Custom Code:

function show_language_selector_flags(){
  $out = '';
  if( !function_exists('icl_get_languages'))
    return $out;

  $languages = icl_get_languages('skip_missing=0&orderby=code');
  if(!empty($languages)){
      foreach($languages as $l){
          if(!$l['active'])
            $out .= '<a href="'.$l['url'].'">';
          $out .= '<img src="'.$l['country_flag_url'].'" height="12" alt="'.$l['language_code'].'" width="18" />';
          if(!$l['active'])
            $out .= '</a>';
      }
  }
  return $out;
}

add_shortcode( 'ts-show-language-selector-flags', 'show_language_selector_flags');

Then in your View's loop or loop template:

 <div class="ts_flags_language_selector">[ts-show-language-selector-flags][/ts-show-language-selector-flags]</div>

And in your View's Loop Editor CSS panel:

.ts_flags_language_selector img{
      margin:1px;
      border:1px solid #333;
}
#1240470

Christian, you guys are amazing at how fast and helpful you are!

Ok, so I set this up but I for the French page to test but I see it's only redirecting to the HOME page still and not the Custom Post Type that needs to be translated.

hidden link

Here is my child theme currently: https://pastebin.com/cmfJ8qWt

#1240511

Okay I see the issue. What if the language translation does not exist - should the flag appear without a link, or should the flag not appear?