Skip to content

Instantly share code, notes, and snippets.

@zArubaru
Created August 30, 2019 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zArubaru/d34489e8242aaf82f2308d9feee0989f to your computer and use it in GitHub Desktop.
Save zArubaru/d34489e8242aaf82f2308d9feee0989f to your computer and use it in GitHub Desktop.
Wordpress: Filter polylang language navigation
<?php
// Only show the provided languages in the language navigation (for polylang).
add_filter(
'wp_nav_menu_objects',
function ( $sorted_menu_items, $args ) {
if ( 'language_navigation' !== $args->theme_location ) {
return $sorted_menu_items;
}
return array_filter(
$sorted_menu_items,
function ( $item ) {
return in_array( $item->lang, [ 'fi', 'en-GB', 'sv-SE' ], true );
}
);
},
10,
2
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment