I have a custom post type. It seems the breadcrumbs have an extra space for a parent page (which does not exist) inserted. You can see this in the image I attached.

What is happening with theis custom post type that is causing this extra, non-existent parent?

Here is my custom page type:

add_action( ‘init’, ‘register_cpt_result’ );

function register_cpt_result() {

$labels = array(
‘name’ => _x( ‘Case Results’, ‘result’ ),
‘singular_name’ => _x( ‘Result’, ‘result’ ),
‘add_new’ => _x( ‘Add New’, ‘result’ ),
‘add_new_item’ => _x( ‘Add New Result’, ‘result’ ),
‘edit_item’ => _x( ‘Edit Result’, ‘result’ ),
‘new_item’ => _x( ‘New Result’, ‘result’ ),
‘view_item’ => _x( ‘View Result’, ‘result’ ),
‘search_items’ => _x( ‘Search Case Results’, ‘result’ ),
‘not_found’ => _x( ‘No case results found’, ‘result’ ),
‘not_found_in_trash’ => _x( ‘No case results found in Trash’, ‘result’ ),
‘parent_item_colon’ => _x( ‘Parent Result:’, ‘result’ ),
‘menu_name’ => _x( ‘Case Results’, ‘result’ ),
);

$args = array(
‘labels’ => $labels,
‘hierarchical’ => true,
‘description’ => ‘My firm’s case results’,
‘supports’ => array( ‘title’, ‘editor’, ‘excerpt’ ),
‘public’ => true,
‘show_ui’ => true,
‘show_in_menu’ => true,

‘show_in_nav_menus’ => true,
‘publicly_queryable’ => true,
‘exclude_from_search’ => true,
‘has_archive’ => true,
‘query_var’ => true,
‘can_export’ => true,
‘rewrite’ => true,
‘capability_type’ => ‘post’
);

register_post_type( ‘result’, $args );
}

Here is my breadcrumbs function:

function crumbs() {
if ((is_page() && ! is_category()) || is_archive() || is_single() || is_single()) {
$crumbs = ”;
$crumbs .= ”;
$crumbs .= ‘Home';
$post_ancestors = get_post_ancestors($post);

if ($post_ancestors) {
$post_ancestors = array_reverse($post_ancestors);
foreach ($post_ancestors as $crumb)
$crumbs .= ”.get_the_title($crumb).”;
}
if (is_category() || is_single()) {
$category = get_the_category();
$crumbs .= ”.$category[0]->cat_name.”;
}
if (!is_category())
$crumbs .= ”.get_the_title().”;
$crumbs .= ”;
$close_crumb = ”;
$open_crumb = ”;
$separator = ‘→';
echo str_replace($close_crumb.$open_crumb, $close_crumb.$separator.$open_crumb, $crumbs);
}
}

Read more here: Custom Post Type and Breadcrumbs Conflict


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: