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.

  • 3
    You're missing the closing </a> in your first code block, the browser will try to fix this by adding markup. Also note that the_title() echoes its value by default, so echo the_title() is redundant. – Milo Nov 2 '18 at 15:07
  • Oh for god sake :D Thanks @Milo - that was the problem! Hah – zigojacko Nov 2 '18 at 15:10
  • also: the_title() echoes the title, by default. Use get_the_title() instead. – Remzi Cavdar Nov 2 '18 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.