Yoast / wordpress-seo

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

Breadcrumbs bug custom post types. #20208

Closed BackuPs closed 1 year ago

BackuPs commented 1 year ago

Please open the functions.php of twenty twenty theme Steps to recreate the issue. 1) Add this code

    `       
    class myCustom_Post{

    public $default_portfolio_slug; 

    public $post_type_portfolio = 'portfolio';
    public $post_type_taxonomy_portfolio = 'portfolio_category';

    public function __construct() {

        add_action( 'init', array(&$this,'portfolio'), 12);
    }

    function portfolio(){

        // Default Slug Names           
        $default_portfolio_slug              =  'portfolio';

        // Slug Names           
        $portfolio_slug              = 'portfolio';     // singular portfolio item

        $labels = array(
            'name' => _x('Portfolio items', 'post type general name', 'theme_admin' ),
            'singular_name' => _x('Portfolio Item', 'post type singular name', 'theme_admin' ),
            'add_new' => _x('Add New', 'portfolio', 'theme_admin' ),
            'add_new_item' => __('Add New Portfolio Item', 'theme_admin' ),
            'edit_item' => __('Edit Portfolio Item', 'theme_admin' ),
            'new_item' => __('New Portfolio Item', 'theme_admin' ),
            'view_item' => __('View Portfolio Item', 'theme_admin' ),
            'search_items' => __('Search Portfolio Items', 'theme_admin' ),
            'not_found' =>  __('No portfolio item found', 'theme_admin' ),
            'not_found_in_trash' => __('No portfolio items found in Trash', 'theme_admin' ), 
            'parent_item_colon' => '',
            'menu_name' => __('Portfolio items', 'theme_admin' ),
        );

        $capabilities = array(
            'publish_posts' => 'theme_publish_portfolios',

            'edit_post' => 'theme_edit_portfolio',
            'edit_posts' => 'theme_edit_portfolios',
            'edit_private_posts' => 'theme_edit_private_portfolios',
            'edit_published_posts' => 'theme_edit_published_portfolios',
            'edit_others_posts' => 'theme_edit_others_portfolios',

            'delete_post' => 'theme_delete_portfolio',
            'delete_posts' => 'theme_delete_portfolios',
            'delete_private_posts' => 'theme_delete_private_portfolios',
            'delete_published_posts' => 'theme_delete_published_portfolios',
            'delete_others_posts' => 'theme_delete_others_portfolios',

            'read_post' => 'theme_read_portfolio',
            'read_private_posts' => 'theme_read_private_portfolios',
        );

        $args = array(
            'labels'            => $labels,
            'singular_label' => __('portfolio', 'theme_admin' ),
            'public' => true,
            'publicly_queryable' => true,
            'exclude_from_search' => false,
            'show_ui' => true,
            'show_in_menu' => true,
            //'menu_position' => 20,
            'capability_type' => 'portfolio',
            'capabilities' => $capabilities,
            'hierarchical' => false,
            'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'comments', 'author', 'page-attributes', 'revisions'),
            'has_archive' => true,
            'rewrite' => array( 'slug' => ! empty($portfolio_slug) ? $portfolio_slug : $default_portfolio_slug, 'with_front' => true, 'pages' => true, 'feeds'=>true ),
            'query_var' => true,
            'can_export' => true,
            'show_in_nav_menus' => true,
        );

        register_post_type('portfolio',$args);

        // Portfolio Categories

        $labels_cat = array(
            'name' => _x( 'Portfolio Categories', 'taxonomy general name', 'theme_admin' ),
            'singular_name' => _x( 'Portfolio Category', 'taxonomy singular name', 'theme_admin' ),
            'search_items' =>  __( 'Search Categories', 'theme_admin' ),
            'popular_items' => __( 'Popular Categories', 'theme_admin' ),
            'all_items' => __( 'All Categories', 'theme_admin' ),
            'parent_item' => null,
            'parent_item_colon' => null,
            'edit_item' => __( 'Edit Portfolio Category', 'theme_admin' ), 
            'update_item' => __( 'Update Portfolio Category', 'theme_admin' ),
            'add_new_item' => __( 'Add New Portfolio Category', 'theme_admin' ),
            'new_item_name' => __( 'New Portfolio Category Name', 'theme_admin' ),
            'separate_items_with_commas' => __( 'Separate Portfolio category with commas', 'theme_admin' ),
            'add_or_remove_items' => __( 'Add or remove portfolio category', 'theme_admin' ),
            'choose_from_most_used' => __( 'Choose from the most used portfolio category', 'theme_admin' ),
            'menu_name' => __( 'Categories', 'theme_admin' ),
        );
        $capabilities_cat = array(
            'manage_terms' => 'theme_manage_portfolio_terms',
            'edit_terms'   => 'theme_edit_portfolio_terms',
            'delete_terms' => 'theme_delete_portfolio_terms',
            'assign_terms' => 'theme_assign_portfolio_terms',
        );

        $args_cat= array(
            'hierarchical' => true,
            'labels' => $labels_cat,
            'capabilities' => $capabilities_cat,
            'public' => false,
            'show_in_nav_menus' => false,
            'show_ui' => true,
            'show_tagcloud' => false,
            'query_var' => true,
            'rewrite' => false,
            'show_admin_column' => true,
        );

        register_taxonomy('portfolio_category','portfolio', $args_cat);

    }   
    }
    new myCustom_Post();

`

2) activate the 20-20 theme and save the permalinks just once.

3) Now create two categories for the portfolio items one named animals and one named videos.

4) Now add a new portfolio item just give it any name

set the animals to that newly created portfolio post and in the post content add the yoast breadcrumb shortcode. Publish the post.

5) If you view the post in the front you will see a empty page and this content showing the breadcrumbs.

afbeelding

I have two questions

Although the categories have no rewrite why does the animal category show up in the breadcrumbs path as a link? Why is there a breadcrumb path called 'Portfolio items' linking to the last portfolio category called video's?

The categories do not have a rewrite => false & public => false

The breadcrumb path called 'Portfolio items' linking to the last portfolio category called video's is there because the register_post_type has a argument called has_archive=> true.

But because of the portfolio category not having a rewrite that should not be in the breadcrumbs path at the first place regardless the has_archive=> true setting because the rewrite (rewrite => false) was set to false in the register_taxonomy arguments.

It does not make any sense that it shows up in the breadcrumb path. I do not understand the why.

Where am i making the mistake or where is yoast breadcrumbs making the mistake and adding the categories to the path. In the Yoast breadcrumb settings the custom category is not shown which is correct.

Please advice.

monbauza commented 1 year ago

We use GitHub exclusively for well-documented bug reports. The reported issue does not contain enough information to be a viable bug report, so we're now closing the report. We have the following support channels:

If you feel like your bug or enhancement is valid and should be reviewed by us, please use the provided templates, read our contribution guidelines, and submit a new issue. Thank you for your understanding.

As for your specific questions:

Also, if the plugin is showing incorrect breadcrumbs after you've changed the registration code of your post type/taxonomy, you may need to reset the indexables table through the Yoast Test Helper plugin.

Lastly, if you have special needs, and the default settings don't allow you to accomplish what you're trying to do, you can use one of the filters available in the plugin to customize your breadcrumbs; for example, the _wpseo_breadcrumblinks or the _wpseo_breadcrumb_singlelink filter. You can find some examples of use on this link.

BackuPs commented 1 year ago

How much information do you need to recreate the bug? I gave you all information. Its a bug When the taxonomy has no rewrite (so rewrite is set to false) then in the breadcrumbs path the category still shows. THAT IS A BUG !! What else do you need so you understand the problem?

"The Yoast breadcrumbs will include the category if you've configured the plugin to do so under Yoast SEO > Settings > Advanced > Breadcrumbs > Breadcrumbs for Post Types (no matter whether rewrites are enabled for the taxonomy)."

I did not and there is nothing todo so because the taxonomy has no rewrite ! Did you even try todo to recreate the issue? Or is this just a default answer to get rid of the problem/issue?

There are other posttypes where i do want to see the category in the breadcrumbs. But not in the one that has no rewrite. The moment i enable rewrite i get a extra option in the yoast breadcrumbs for that custom posttype.