Custom Post - Full category in breadcrumbs

I added some functionality to be able to display the post type and category for the breadcrumbs.

function get_display_post_type() {
    global $post;
    $post_type = get_post_type_object(get_post_type($post));
    if ($post_type) {
        return $post_type->labels->singular_name;
    }
    return '';
}

function get_all_parent_categories() {
    $categories = get_the_category(); 
    $parent_categories = array();

    if (!empty($categories)) {
        foreach ($categories as $category) {
            if ($category->parent) {
                $parent_category = get_category($category->parent);
                $parent_categories[] = $parent_category->name;
            }
        }
    }

    if (!empty($parent_categories)) {
        return implode('/ ', $parent_categories);
    } else {
        return '';
    }
}

And here’s how I use them

/{echo:get_display_post_type}/{echo:get_all_parent_categories}/{post_terms_category}/

Hope this helps you too

3 Likes