Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.
2 edited body
source | link

I'm trying to construct a breadcrumb trail where some of the paths consist of parent/child custom post types.

For example:

else if ( is_singular( 'resort' ) ) {
    global $post;
    $post_data = get_post($post->post_parent);
    $parent_title = $post_data->post_title;
    $parent_slug = $post_data->post_name;

    echo '<li><a href="/destinations/" title="' . __('Destinations', 'bookyourtravel') . '">' . __('Destinations', 'bookyourtravel') . '</a></li>';
    echo '<li><a href="/destinations/' . $parent_slug . '/" title="' . $parent_title . ' Villas">' . $parent_title . '</li>';
}

Whilst this outputs exactly what I'm after, for example:

Destinations > $parent_title

When I try to get the current page's title for the last path in the breadcrumb simplesimply with:

echo "<li>";
echo the_title();
echo "</li>";

It ends up duplicating the second destination > $parent_title path above...

I attach a screenshot of the source code to illustrate this problem.

It seems by the usage of the_title(), it seems to wrap any mention of the current page title (Playa Blanca) in a link which links back to the parent page (Lanzarote) which hopefully can be seen in the image.

enter image description here

Why can't the above just echo the current page title (the_title()) at the end of the breadcrumb trail properly?

I just want 'Playa Blanca' to be at the end of the breadcrumb trail not linked and not interfering with anything else on the page.

I'm trying to construct a breadcrumb trail where some of the paths consist of parent/child custom post types.

For example:

else if ( is_singular( 'resort' ) ) {
    global $post;
    $post_data = get_post($post->post_parent);
    $parent_title = $post_data->post_title;
    $parent_slug = $post_data->post_name;

    echo '<li><a href="/destinations/" title="' . __('Destinations', 'bookyourtravel') . '">' . __('Destinations', 'bookyourtravel') . '</a></li>';
    echo '<li><a href="/destinations/' . $parent_slug . '/" title="' . $parent_title . ' Villas">' . $parent_title . '</li>';
}

Whilst this outputs exactly what I'm after, for example:

Destinations > $parent_title

When I try to get the current page's title for the last path in the breadcrumb simple with:

echo "<li>";
echo the_title();
echo "</li>";

It ends up duplicating the second destination > $parent_title path above...

I attach a screenshot of the source code to illustrate this problem.

It seems by the usage of the_title(), it seems to wrap any mention of the current page title (Playa Blanca) in a link which links back to the parent page (Lanzarote) which hopefully can be seen in the image.

enter image description here

Why can't the above just echo the current page title (the_title()) at the end of the breadcrumb trail properly?

I just want 'Playa Blanca' to be at the end of the breadcrumb trail not linked and not interfering with anything else on the page.

I'm trying to construct a breadcrumb trail where some of the paths consist of parent/child custom post types.

For example:

else if ( is_singular( 'resort' ) ) {
    global $post;
    $post_data = get_post($post->post_parent);
    $parent_title = $post_data->post_title;
    $parent_slug = $post_data->post_name;

    echo '<li><a href="/destinations/" title="' . __('Destinations', 'bookyourtravel') . '">' . __('Destinations', 'bookyourtravel') . '</a></li>';
    echo '<li><a href="/destinations/' . $parent_slug . '/" title="' . $parent_title . ' Villas">' . $parent_title . '</li>';
}

Whilst this outputs exactly what I'm after, for example:

Destinations > $parent_title

When I try to get the current page's title for the last path in the breadcrumb simply with:

echo "<li>";
echo the_title();
echo "</li>";

It ends up duplicating the second destination > $parent_title path above...

I attach a screenshot of the source code to illustrate this problem.

It seems by the usage of the_title(), it seems to wrap any mention of the current page title (Playa Blanca) in a link which links back to the parent page (Lanzarote) which hopefully can be seen in the image.

enter image description here

Why can't the above just echo the current page title (the_title()) at the end of the breadcrumb trail properly?

I just want 'Playa Blanca' to be at the end of the breadcrumb trail not linked and not interfering with anything else on the page.

1
source | link

Using the_title() and fetching the parent page's title and slug to construct breadcrumbs

I'm trying to construct a breadcrumb trail where some of the paths consist of parent/child custom post types.

For example:

else if ( is_singular( 'resort' ) ) {
    global $post;
    $post_data = get_post($post->post_parent);
    $parent_title = $post_data->post_title;
    $parent_slug = $post_data->post_name;

    echo '<li><a href="/destinations/" title="' . __('Destinations', 'bookyourtravel') . '">' . __('Destinations', 'bookyourtravel') . '</a></li>';
    echo '<li><a href="/destinations/' . $parent_slug . '/" title="' . $parent_title . ' Villas">' . $parent_title . '</li>';
}

Whilst this outputs exactly what I'm after, for example:

Destinations > $parent_title

When I try to get the current page's title for the last path in the breadcrumb simple with:

echo "<li>";
echo the_title();
echo "</li>";

It ends up duplicating the second destination > $parent_title path above...

I attach a screenshot of the source code to illustrate this problem.

It seems by the usage of the_title(), it seems to wrap any mention of the current page title (Playa Blanca) in a link which links back to the parent page (Lanzarote) which hopefully can be seen in the image.

enter image description here

Why can't the above just echo the current page title (the_title()) at the end of the breadcrumb trail properly?

I just want 'Playa Blanca' to be at the end of the breadcrumb trail not linked and not interfering with anything else on the page.