How to display breadcrumb on category?

If you’re dealing with the default “Category” taxonomy and the post post type, then you can get the post’s attached category terms with get_the_category().

$categories = has_category( $post ) ? get_the_category( $post ) : array();

The has_category() check is there just to fend off other post type posts.

get_the_category() gives you an array of categories as WP_Terms. They are probably not in any particular order and there might terms from different hierarchy levels in the list. So for example use the first term or conjure up some logic to order the terms in the desired order, before rendering them all.

To get the category link you can use get_category_link(). The category name can be read from the WP_Term object and used as the anchor text.

$category_link = $categories
    ? sprintf(
        '<a href="%s">%s</a>',
        esc_url( get_category_link( $categories[0] ) ),
        esc_html( $categories[0]->name )
    )
    : '';

If you have other taxonomies and post types, then use has_term(), get_the_terms(), and get_term_link().

tech