wp-polylang-translate-rewrite-slugs
wp-polylang-translate-rewrite-slugs copied to clipboard
tags and category support
it would be awesome if tags and categories would be supported as well!
+1
+1
See the pro version of Polylang Pro, which has this feature.
Before adding this plugin I managed to add a sub-category to a custom taxonomies slug but now it outputs %project_cateogry% in the URL. Maybe the following code help kicking off a solution:
// renaming project custom post type
// https://ayanize.com/snippets/how-to-rename-project-post-type-to-anything-or-create-a-new-post-type-with-divi-page-builder-on/
// And add sub-category https://www.elegantthemes.com/forum/viewtopic.php?f=187&t=728022&hilit=portfolio+category&p=4008597#p4008597
function rename_project_cpt() {
register_post_type( 'project',
array(
'labels' => array(
'name' => __( 'Immobilien', 'divi' ), // change the text portfolio to anything you like
'singular_name' => __( 'Immobilie', 'divi' ), // change the text portfolio to anything you like
),
'has_archive' => true,
'hierarchical' => true,
'menu_icon' => 'dashicons-building', // you choose your own dashicon
'public' => true,
'rewrite' => array( 'slug' => 'immobilien/%project_category%', 'with_front' => false ), // change the text portfolio to anything you like
'supports' => array(),
));
}
add_action( 'init', 'rename_project_cpt' );
function wpa_show_permalinks( $post_link, $post ){
if ( is_object( $post ) && $post->post_type == 'project' ){
$terms = wp_get_object_terms( $post->ID, 'project_category' );
if( $terms ){
return str_replace( '%project_category%' , $terms[0]->slug , $post_link );
}
}
return $post_link;
}
add_filter( 'post_type_link', 'wpa_show_permalinks', 1, 2 );
// Translate Custom taxonomy Slug
// https://github.com/KLicheR/wp-polylang-translate-rewrite-slugs/blob/master/README.md
add_filter('pll_translated_post_type_rewrite_slugs', function($post_type_translated_slugs) {
// Add translation for "product" post type.
$post_type_translated_slugs = array(
'project' => array(
'en' => array(
'has_archive' => true,
'rewrite' => array(
'slug' => 'estate/%project_category%'
),
),
),
);
return $post_type_translated_slugs;
});
add_filter( 'post_type_link', 'wpa_show_permalinks', 11, 4 );
the priority must be lower otherwise you cannot correct the url because it still does not contain %project_category%.