Make Custom Post Types Translatable in Polylang
Turns on Polylang translation for custom post types registered by your theme or a plugin, even when they do not appear in Languages > Settings.
Opens WPIDE on
Code
$wpide_types = array( 'book', 'portfolio' ); // Post type keys.
add_filter( 'pll_get_post_types', function ( $post_types, $is_settings ) use ( $wpide_types ) {
foreach ( $wpide_types as $type ) {
if ( $is_settings ) {
unset( $post_types[ $type ] ); // Managed here, so hide it from the settings list.
} else {
$post_types[ $type ] = $type;
}
}
return $post_types;
}, 10, 2 );
Notes
Use the post type keys (e.g. book, portfolio). They disappear from Polylang's settings list because this snippet now manages them.
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.