I have a site with two languages, but it's pointless to show the name of the currently selected language in the language switcher block. How can I hide it?


The links generated by the Language API are alterable via hook_language_switch_links_alter(), so you can do this:

 * Implements hook_language_switch_links_alter().
function MYMODULE_language_switch_links_alter(array &$links, $type, $path) {
  global $language;


[Drupal 8]:

Implement hook_language_switch_links_alter in a custom module like this:

 * Perform alterations on language switcher links.
 * A language switcher link may need to point to a different path or use a
 * translated link text before going through the link generator, which will
 * just handle the path aliases.
 * @param array $links
 *   Nested array of links keyed by language code.
 * @param string $type
 *   The language type the links will switch.
 * @param \Drupal\Core\Url $url
 *   The URL the switch links will be relative to.
function hook_language_switch_links_alter(array &$links, $type, \Drupal\Core\Url $url) {
  $language_interface = \Drupal::languageManager()->getCurrentLanguage();
  $current_language_id = $language_interface->getId();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.