The problem: All languages that have published content show up in the language switcher which is situated in the main navigation bar. As I only have a few pages in Swedish and users are directed directly to them, I would like to remove the link to the Swedish language translation from the main navigation.
Solution: After searching forums and reading posts here on Stack Overflow, it seems that the best way to go (if I've understood correctly) is to create a function in the theme functions.php file and add a filter to the switcher that removes Swedish if found. This is also where any wise words would be appreciated; how to go about creating an appropriate filter?
This is what I have so far. However, my site crashes when I try it out.
function trim_language_switcher() {
$del_val = 'sv'; // Value to be deleted
if(function_exists('pll_the_languages')) {
$languages = pll_the_languages(array('raw'=>) // Get raw data as array
if (($key = array_search($del_val, $languages)) !== false) { // Get key for value
unset($languages[$key]);
}
return $languages;
}
}
add_filter( 'pll_the_languages', 'trim_language_switcher' );
Any help is greatly appreciated!