wordpress-seo
wordpress-seo copied to clipboard
Custom post type breadcrumbs are not translatable anymore using Yoast SEO and WPML
- [x] I've read and understood the contribution guidelines.
- [x] 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?
- 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' );
- Add breadcrumbs to your theme (I'm using default Twenty Twenty):
<?php
if ( function_exists('yoast_breadcrumb') ) {
yoast_breadcrumb( '<p id="breadcrumbs">','</p>' );
}
?>
- 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).
- 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):
- [x] Chrome
- [x] Firefox
- [x] 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
I do not think this is up to us to fix, as this is not our functionality. Seems kind of the same as https://github.com/Yoast/wordpress-seo/issues/15186 . @jono-alderson what do you think?
I don't know enough about how this worked/works to have an opinion, sorry!
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!
@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.
Thanks for the confirmation dejann. In that case I've created a new issue specific to the bug I've found: https://github.com/Yoast/wordpress-seo/issues/15627
@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.
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.