Make Custom Taxonomies Translatable in Polylang
Turns on Polylang translation for custom taxonomies, such as product types or event categories, that are not offered in Languages > Settings.
Opens WPIDE on
Code
$wpide_taxonomies = array( 'genre', 'location' ); // Taxonomy keys.
add_filter( 'pll_get_taxonomies', function ( $taxonomies, $is_settings ) use ( $wpide_taxonomies ) {
foreach ( $wpide_taxonomies as $taxonomy ) {
if ( $is_settings ) {
unset( $taxonomies[ $taxonomy ] );
} else {
$taxonomies[ $taxonomy ] = $taxonomy;
}
}
return $taxonomies;
}, 10, 2 );
Notes
Use the taxonomy keys; they are hidden from Polylang's settings list because this snippet manages them. Translate existing terms afterwards in each taxonomy's screen.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.