• Resolved akalwp

    (@akalwp)


    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 structure

    https://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.1

    Below 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;
    }
    • This topic was modified 5 years, 12 months ago by akalwp.

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi,

    We would like some more information.

    A. Are all your non-Yoast plugins and themes also updated?

    B. Can you confirm you are using WordPress 5.1.1? You can check by clicking on the W in the top left and selecting About. If you need to update, please check with your host provider.?Please know that if you are using an older version of WordPress Core you may experience unexpected behavior with Yoast.?This guide explains more:?https://yoast.com/why-we-dont-support-old-wordpress-versions/.

    C. We see on https://campings-psj.gatcom.fr/en/residential/buy-sell-mobil-home-accessories/offers-parc-montana/terrasse-n1/ you have the English Word Residential as part of the breadcrumb pathway. We see it goes to https://campings-psj.gatcom.fr/residentiel/

    To clarify, you want that permalink for it to go to: https://campings-psj.gatcom.fr/en/residential/? Correct?

    D. We see you have added some kind of custom breadcrumb called: nicdark_breadcrumbs white. See image: https://pasteboard.co/I7dcz8n.png.

    Did you also implement the Yoast SEO Breadcrumbs too using this guide: https://kb.yoast.com/kb/implement-wordpress-seo-breadcrumbs/

    Thread Starter akalwp

    (@akalwp)

    Hi,
    many thanks for your reply.

    A. Yes everything is up to date
    B. Yes I’m using WordPress 5.1.1
    C. Right, that’s the issue. And yes, the permalink should link to /en/residential/ when I’m under the english version. Currently, the permalink in the english verison send to the french version of the page (/residentiel/)
    D. Yes but it’s just about CSS/Class style. Yes I’ve followed the guide.

    I supposed there is someting wrong with my code, on the redirection part; because the /residentiel/ is hard coded, maybe I should add the condition “if language = eng, do this” but I’m not good enought… If you have any ideas ?

    Best regards
    Akal

    Hi,

    We are not sure why the issue is happening. We are not sure if there is a conflict, a bug between Yoast and WPML or if there is an issue with how you may have hard-coded the /residentiel/.

    Can you try and gather as much information for us as possible? Please perform the following:

    1. Make sure the issue doesn’t persist when Yoast SEO is disabled.

    2. Check for conflicts.

    3. If there is a conflict with a plugin or a theme, you can create a new GitHub issue for our developers. Please report the issue to a third party developer as well.

    If you didn’t find any conflicts or errors, we think the issue is specific to your site. We’d need to investigate further but are unable to do so on these forums. You can purchase Yoast SEO Premium and receive our Premium email support and we can help you further.

    Plugin Support amboutwe

    (@amboutwe)

    This thread has been marked as resolved due to lack of activity.

    You’re always welcome to re-open this topic. Please read this post before opening a new request.

    Thanks for understanding!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom Post Type – Yoast SEO breadcrumbs use wrong slug with WPML translation’ is closed to new replies.