Lang Forge can translate any custom post type. Until a list is saved in Lang Forge > Settings > Content & Notifications > Translatable Post Types, every public post type except attachments is enabled; after you save a list, only the post types in it are, plus product while WooCommerce is active and the LearnDash types while LearnDash is active. Register your custom post types for translation either through the admin or programmatically.
Enabling via Filter
/**
* Add custom post types to the translatable list.
*
* @param array $post_types Array of post type slugs
* @return array Modified array
*/
add_filter('langforge_translatable_post_types', function ($post_types) {
$post_types[] = 'portfolio';
$post_types[] = 'testimonial';
$post_types[] = 'event';
return $post_types;
});| Parameter | Type | Description |
|---|---|---|
$post_types | array | Array of post type slugs currently enabled for translation. It is the only argument; the filter runs each time Lang Forge builds the list |
| Return Type | Description |
|---|---|
array | Modified array of post type slugs |
Enabling via Options
// Programmatically enable a post type. The option is empty until a list has been saved in Settings,
// so start from the effective list: saving only ['portfolio'] would leave every other type out
$translatable = LANGFORGE_Core::get_translatable_post_types();
if (!in_array('portfolio', $translatable, true)) {
$translatable[] = 'portfolio';
update_option('langforge_translatable_post_types', $translatable);
}Registering a Translation-Ready Custom Post Type
When registering your custom post type, ensure it has show_in_rest for REST API support and proper rewrite rules for language prefixes:
add_action('init', function () {
register_post_type('portfolio', [
'label' => 'Portfolio',
'public' => true,
'show_in_rest' => true,
'has_archive' => true,
'rewrite' => ['slug' => 'portfolio'],
'supports' => ['title', 'editor', 'thumbnail', 'excerpt'],
]);
});
// Enable it for translation
add_filter('langforge_translatable_post_types', function ($types) {
$types[] = 'portfolio';
return $types;
});// Create a portfolio item and its English translation
$ru_post_id = wp_insert_post([
'post_type' => 'portfolio',
'post_title' => 'Мой проект',
'post_status' => 'publish',
]);
LANGFORGE_Post_Translation::instance()->set_post_language($ru_post_id, 'ru');
$en_post_id = wp_insert_post([
'post_type' => 'portfolio',
'post_title' => 'My Project',
'post_status' => 'publish',
]);
LANGFORGE_Post_Translation::instance()->set_post_language($en_post_id, 'en');
// Link them as translations
LANGFORGE_Post_Translation::instance()->link_translations($ru_post_id, $en_post_id);// Check if a post type is enabled for translation (the option is empty until a list is saved in Settings,
// so ask Lang Forge for the effective list, with the filter applied)
$translatable = LANGFORGE_Core::get_translatable_post_types();
if (in_array('product', $translatable, true)) {
// WooCommerce products are translatable
}—