Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom post type breadcrumbs are not translatable anymore using Yoast SEO and WPML #15582

Open
5 of 9 tasks
dejann opened this issue Jun 29, 2020 · 7 comments
Open
5 of 9 tasks

Comments

@dejann
Copy link

dejann commented Jun 29, 2020

  • I've read and understood the contribution guidelines.
  • I've searched for any related issues and avoided creating a duplicate issue.

Please give us a description of what happened.

Please note this was working fine in Yoast SEO version 12.x.x after updating to 14.x.x it doesn't work anymore.
After adding breadcrumbs to the theme and switching languages (in WPML) breadcrumbs don't display translated version for custom post type.

Please describe what you expected to happen and why.

Breadcrumb strings should be translatable as they did in version 12.x.x.

How can we reproduce this behavior?

  1. Create a custom post type. This is the code that I'm using:
function movie_post_type() {
 
    $labels = array(
        'name'                => _x( 'Movies', 'Post Type General Name', 'twentytwenty' ),
        'singular_name'       => _x( 'Movie', 'Post Type Singular Name', 'twentytwenty' ),
        'menu_name'           => __( 'Movies', 'twentytwenty' ),
        'parent_item_colon'   => __( 'Parent Movie', 'twentytwenty' ),
        'all_items'           => __( 'All Movies', 'twentytwenty' ),
        'view_item'           => __( 'View Movie', 'twentytwenty' ),
        'add_new_item'        => __( 'Add New Movie', 'twentytwenty' ),
        'add_new'             => __( 'Add New', 'twentytwenty' ),
        'edit_item'           => __( 'Edit Movie', 'twentytwenty' ),
        'update_item'         => __( 'Update Movie', 'twentytwenty' ),
        'search_items'        => __( 'Search Movie', 'twentytwenty' ),
        'not_found'           => __( 'Not Found', 'twentytwenty' ),
        'not_found_in_trash'  => __( 'Not found in Trash', 'twentytwenty' ),
    );
     
// Set other options for Custom Post Type
     
    $args = array(
        'label'               => __( 'movies', 'twentytwenty' ),
        'description'         => __( 'Movie news and reviews', 'twentytwenty' ),
        'labels'              => $labels,
        // Features this CPT supports in Post Editor
        'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
        // You can associate this CPT with a taxonomy or custom taxonomy. 
        'taxonomies'          => array( 'genres' ),
        /* A hierarchical CPT is like Pages and can have
        * Parent and child items. A non-hierarchical CPT
        * is like Posts.
        */ 
        'hierarchical'        => false,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 5,
        'can_export'          => true,
        'has_archive'         => true,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'capability_type'     => 'post',
        'show_in_rest' => true,
 
    );
     
    // Registering your Custom Post Type
    register_post_type( 'movies', $args );
 
}
// Hooking up our function to theme setup
add_action( 'init', 'movie_post_type' );
  1. Add breadcrumbs to your theme (I'm using default Twenty Twenty):
<?php
if ( function_exists('yoast_breadcrumb') ) {
  yoast_breadcrumb( '<p id="breadcrumbs">','</p>' );
}
?>
  1. Translate custom post type string "Movie" to another language using WPML String Translation (both WPML Multilingual CMS and WPML String Translation plugins must be installed).
  2. Try switching between languages in WMPL. Default post type and taxonomies such as "Categories" and "Tags" in breadcrumbs can be translated fine but not Custom post types.

Technical info

  • If relevant, which editor is affected (or editors):
  • Classic Editor
  • Gutenberg
  • Classic Editor plugin
  • Which browser is affected (or browsers):
  • Chrome
  • Firefox
  • Safari
  • Other

Used versions

  • WordPress version: 5.4.2
  • Yoast SEO version: 14.4.1
  • WPML Multilingual CMS: 4.3.15
  • WPML String Translation: 3.0.11
  • Tested with theme: Twenty Tweny
@Djennez
Copy link
Member

Djennez commented Jun 29, 2020

I do not think this is up to us to fix, as this is not our functionality. Seems kind of the same as #15186 . @jono-alderson what do you think?

@jonoalderson
Copy link

I don't know enough about how this worked/works to have an opinion, sorry!

@pjrobertson
Copy link

I've been working on a breadcrumb issue with Qtranslate-xt and Yoast 14.0+. I have found the issue with breadcrumbs lies with this line of code:

https://github.com/Yoast/wordpress-seo/blob/trunk/src/builders/indexable-post-builder.php#L133

Upon saving a post, Yoast is saving a hard copy of the post's title in its indexables database. For some multi-lingual plugins (like Qtranslate-xt), this hard copy will be saved based on whatever language the admin UI was set to at the time.

A solution would be to avoid using get_the_title in this context, but to use $post->post_title instead. I can confirm that this fixes the issue.

It fixes cases where get_the_title returns titles other than what is expected. E.g. prefixed with Private: for private posts.

If you do not want to change this part of the code, then I suggest you add in a filter to filter the breadcrumb title.

Thanks!

@dejann
Copy link
Author

dejann commented Jul 6, 2020

@pjrobertson Thanks for taking a look. Unfortunately I don't have issues with post titles but with custom post type and taxonomy displayed inside breadcrumbs. Everything works fine with regular posts and categories but not with custom post and taxonomies.

If anyone from Yoast team could take a look if breadcrumb titles are called as untranslatable sting that would be great.

@pjrobertson
Copy link

Thanks for the confirmation dejann. In that case I've created a new issue specific to the bug I've found: #15627

@pjrobertson
Copy link

@Djennez @jono-alderson all that is needed to solve this from the plugin's point of view is a filter to be able to alter the value that goes into the indexables on save.

For the breadcrumbs issue, some kind of filter that for $indexable->breadcrumb_title is all that's required.

@mrwweb
Copy link

mrwweb commented Jul 22, 2024

It's 2024 and I believe I am experiencing the same issue. Using Yoast with Polylang Pro, I have a custom post type where the breadcrumb for a single CPT post is {Post Type} > {Single Post Title}. Unfortunately, it appears that the "{Post Type}" is not translated, despite the post type being fully translated into the relevant language.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants