Yoast / wordpress-seo

Yoast SEO for WordPress
https://yoast.com/wordpress/plugins/seo/
Other
1.77k stars 890 forks source link

Incorrect breadcrumbs category #18992

Closed arthurshlain closed 2 years ago

arthurshlain commented 2 years ago

Please give us a description of what happened.

I found the issue when breadcrumbs category at single-post.php template is wrong. The category name in breadcrumbs refers to custom taxonomy, registered for page post type only:

register_taxonomy('page_type', ['page'], [...]);

In DB post_meta table I found meta key _yoast_wpseo_primary_category with value that refers to page_type custom taxonomy record, not category. I did not make any changes to the database, it is probably so indexed by seo plugin.

How it's looking at page:

Front page » Product Page » The post title

where Product Page — is page_type taxonomy.

How expected:

Front page » News » The post title

where News — is category taxonomy.

Please describe what you expected to happen and why.

I expected to see correct category in breadcrumbs for single-post.php

How can we reproduce this behavior?

This is approximate list:

  1. Regiter custom taxonomy for page post type (example below).
  2. Add some posts and categories.
  3. Install seo plugin and make optimisation.
  4. Enable Twenty Twenty 2.0 theme and setup widget with shortcode [wpseo_breadcrumb]
  5. View single post type and check pagination HTML.

For example, my site has 2 post categories and 2 custom taxonomy records.

Example code for reproduce step 1

add_action('init', function(){
  register_taxonomy('page_type', ['page'], [
    'label' => '',
    'labels' => [
      'name' => 'Page Type',
      'singular_name' => 'Page Type',
    ],
    'description' => 'Types of Page',
    'publicly_queryable'    => false,
    'show_in_nav_menus'     => false,
    'show_ui'               => true,
    'show_in_menu'          => true,
    'show_tagcloud'         => false,
    'show_in_quick_edit'    => false,
    'hierarchical'          => false,
    'rewrite'               => true,
    'capabilities'          => array(),
    'meta_box_cb'           => 'post_categories_meta_box',
    'show_admin_column'     => true,
    'show_in_rest'          => true,
    'rest_base'             => null,
  ]);
});

Technical info

Used versions

mmikhan commented 2 years ago

I am afraid I couldn't reproduce the issue using the steps you provided. I created a new custom taxonomy for Pages using the example code snippet you provided. I published new pages and made sure the new pages had the relevant custom taxonomy. I selected the relevant custom taxonomy for page post type from the Yoast SEO breadcrumbs setting to ensure the relevant custom taxonomy appears in the breadcrumb path.

When visiting the single page, I see the breadcrumb path as expected [Home](https://rgetic-eel-dohe.instawp.xyz/) » [Chrome](https://rgetic-eel-dohe.instawp.xyz/page_type/chrome/) » One. Chrome is the new custom taxonomy generated using the code snippet you provided.

Did I miss anything?

arthurshlain commented 2 years ago

Why your middle link is /page_type/? It's the my problem. But you need to check it on single post, not page. I have ~20 posts (not pages) where /page_type/ exists in breadcrumbs.

It's hard to reproduce, because new posts have correct breadcrumbs.

I would recommend just taking a look at the code for a possible erroneous taxonomy assignment in the _yoast_wpseo_primary_category meta value, or wait until someone maybe have same issue.

My new posts have this structure: [Home](https://domain.xyz/) » [Techhub](https://domain.xyz/techhub/) » Post Title

Old/not modified posts has this structure: [Home](https://domain.xyz/) » [Product Page](https://domain.xyz/page_type/product/) » Post Title

My permalink structure is /%category%/%postname%/, prefixes is empty, but I maybe miss say I use this plugin (installed before SEO plugin) to remove cateogry base https://wordpress.org/plugins/remove-category-url/

arthurshlain commented 2 years ago

Can I remove _yoast_wpseo_primary_category meta values from databse to fix my breadcrumbs?

mmikhan commented 2 years ago
arthurshlain commented 2 years ago

In register_taxonomy('page_type', ['page']) the second parameter means the taxonomy should be associated with Pages only. It's impossible to check it, because no related metabox shown for it.

Resetting indexables not solves this issue, the _yoast_wpseo_primary_category values still exists in meta table.

mmikhan commented 2 years ago

Since I have a hard time reproducing the issue, it is time to move the issue to our support team. If you own a premium subscription, you can reach us at support@yoast.com email address. If not, the public forum will also do the job.