Custom Post Type – Yoast SEO breadcrumbs use wrong slug with WPML translation
-
Hi,
I searched but didn’t find solutions… please I really need help here…
I can’t figured out if there is an issue in my code or if I’m fighting against a WPML or Yoast bug side.I’m using the Yoast Breadcrumbs for my custom post types & taxonomies.
Here is my structurehttps://campings-psj.gatcom.fr/residentiel/ => ‘residentiel’ is a page.
https://campings-psj.gatcom.fr/residentiel/achat-vente-mobil-home-accessoires/ => ‘achat-vente-mobil-home-accessoires’ is the parent category for my custom post types
https://campings-psj.gatcom.fr/residentiel/achat-vente-mobil-home-accessoires/offres-parc-montana/ => ‘offres-parc-montana’ is one of its child
https://campings-psj.gatcom.fr/residentiel/achat-vente-mobil-home-accessoires/offres-parc-montana/terrasse-n1/ => ‘terrasse-n1’ is a custom post type.As you can see, everything works great, after long time spent on it, and multiple headaches.
And it is also the same when I use translation, here in english (original is french):
https://campings-psj.gatcom.fr/en/residential/
https://campings-psj.gatcom.fr/en/residential/buy-sell-mobil-home-accessories/
https://campings-psj.gatcom.fr/en/residential/buy-sell-mobil-home-accessories/offers-parc-montana/
https://campings-psj.gatcom.fr/en/residential/buy-sell-mobil-home-accessories/offers-parc-montana/terrasse-n1/
On those pages (all the same), please, check the permalink of “Residential” in the Yoast breadcrumbs. As you can see, this is not the english version /residential/ that is shown but the french /residentiel/.
Do you have any idea what can cause this issue ? How could I fix it ? According to WPML it is literally not their business… I hope I will receive a better answer here ! Does someone can help me, please ?Wordpress 5.1.1
Yoast 10
WPML 4.2.4.1Below my Custom Post type & Taxonomy plugin file =>
<?php /*Plugin Name: Akal CPT for PSJ / cpt-akal Theme Description: This plugin registers "MH & ACC" post type. It is designed for Camping Parc saint James / cpt-akal theme and should not be used for other customer / theme without modifications. If disabled, all posts under "Achat Vente Mobil Home et Accessoires" will result 404 not found. Version: 1.0 License: GPLv2 */ /**************************/ /*********HEBERGEMENTS********/ /************************/ //CUSTOM TAXONOMY CREATION TYPE => GENERATION DES CATEGORIES function mh_acc_type() { $labels = array( 'name' => _x( 'MH & ACC Types', 'Taxonomy General Name', 'cpt-akal' ), 'singular_name' => _x( 'MH & ACC Type', 'Taxonomy Singular Name', 'cpt-akal' ), 'menu_name' => __( 'MH & ACC Types', 'cpt-akal' ), 'all_items' => __( 'All Items', 'cpt-akal' ), 'parent_item' => __( 'Parent Item', 'cpt-akal' ), 'parent_item_colon' => __( 'Parent Item:', 'cpt-akal' ), 'new_item_name' => __( 'New Item Name', 'cpt-akal' ), 'add_new_item' => __( 'Add New Item', 'cpt-akal' ), 'edit_item' => __( 'Edit Item', 'cpt-akal' ), 'update_item' => __( 'Update Item', 'cpt-akal' ), 'view_item' => __( 'View Item', 'cpt-akal' ), 'separate_items_with_commas' => __( 'Separate items with commas', 'cpt-akal' ), 'add_or_remove_items' => __( 'Add or remove items', 'cpt-akal' ), 'choose_from_most_used' => __( 'Choose from the most used', 'cpt-akal' ), 'popular_items' => __( 'Popular Items', 'cpt-akal' ), 'search_items' => __( 'Search Items', 'cpt-akal' ), 'not_found' => __( 'Not Found', 'cpt-akal' ), 'no_terms' => __( 'No items', 'cpt-akal' ), 'items_list' => __( 'Items list', 'cpt-akal' ), 'items_list_navigation' => __( 'Items list navigation', 'cpt-akal' ), ); $args = array( 'labels' => $labels, 'hierarchical' => true, 'public' => true, 'show_ui' => true, 'show_admin_column' => true, 'show_in_nav_menus' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'residentiel', 'hierarchical' => true, ), ); register_taxonomy( 'mh_acc_type', array( 'mh_accs_post_type' ), $args ); } add_action( 'init', 'mh_acc_type', 0 ); //CUSTOM POST Type = MH & ACC => GENERATION DES SINGLE POST function akal_cpt_mh_acc() { $labels = array( 'name' => _x('Résidentiel', 'cpt-akal'), 'singular_name' => _x('Résidentiel', 'cpt-akal'), 'add_new' => _x('Add MH & ACC', 'cpt-akal'), 'add_new_item' => __('Add MH & ACC'), 'edit_item' => __('Edit MH & ACC'), 'new_item' => __('New MH & ACC'), 'view_item' => __('View MH & ACC'), 'search_items' => __('Search MH & ACC'), 'not_found' => __('Nothing found'), 'not_found_in_trash' => __('Nothing found in Trash'), 'parent_item_colon' => '' ); $args = array( 'labels' => $labels, 'taxonomies' => array('mh_acc_type', 'post_tag'), 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_rest' => true, 'rest_base' => '', 'query_var' => true, 'rewrite' => true, 'capability_type' => 'page', 'hierarchical' => true, 'menu_position' => null, 'has_archive' => 'residentiel/.', 'supports' => array('title', 'editor', 'thumbnail', 'comments', 'revisions', 'custom-fields', 'page-attributes', 'excerpt'), 'rewrite' => array('slug' => _x( 'residentiel/achat-vente-mobil-home-accessoires/%mh_acc_type%', 'cpt-akal' )), //FOR WPML '_builtin' => false, ); register_post_type( 'mh_accs_post_type' , $args ); } add_action('init', 'akal_cpt_mh_acc'); //REDIRECTION %mh_acc_type% function custom_post_link($post_link, $id = 0) { $post = get_post($id); if($terms = wp_get_object_terms($post->ID, 'mh_acc_type')) { $mh_acc_type = $terms[0]->slug; //Replace the query var surrounded by % with the slug of //the first taxonomy it belongs to. return str_replace('%mh_acc_type%', $mh_acc_type, $post_link); } //If all else fails, just return the $post_link. return $post_link; } add_filter('post_type_link', 'custom_post_link', 1, 3); add_filter('rewrite_rules_array', 'mmp_rewrite_rules'); function mmp_rewrite_rules($rules) { $newRules = array(); $newRules['residentiel/(.+)/(.+)/(.+)/?$'] = 'index.php?mh_accs_post_type=$matches[3]'; $newRules['residentiel/(.+)/(.+)/?$'] = 'index.php?mh_acc_type=$matches[2]'; return array_merge($newRules, $rules); } //Register template single-creations.php for all creations CPT function load_mh_accs_template($template) { global $post; if ($post->post_type == "mh_accs_post_type" && $template !== locate_template(array("single-creations.php"))) { return plugin_dir_path( __FILE__ ) . "single-creations.php"; } return $template; } add_filter('single_template', 'load_mh_accs_template'); //Register template creation_type.php for all creations CPT Taxonomy Archives add_filter('taxonomy_template', 'load_mh_acc_type_template'); function load_mh_acc_type_template($template) { if (is_tax ('mh_acc_type')) { $template = plugin_dir_path( __FILE__ ) . "archive-creation_type.php"; } return $template; }
The page I need help with: [log in to see the link]
- The topic ‘Custom Post Type – Yoast SEO breadcrumbs use wrong slug with WPML translation’ is closed to new replies.