php – Stop breadcrumb function retrieving custom post type template name


I have created a function that pulls in the breadcrumb of a page/post. However, I am having a problem where it appears to pull in the custom post-type template name rather than the actual name of the post.

    function get_breadcrumb() {

    global $post;

    $page_title = get_the_title($post->ID);
    $url = $protocol;

    if($post->post_parent) {
        $parent_id = $post->post_parent;

        while ($parent_id) {
            $page = get_page($parent_id);
            $breadcrumbs[] = '<a href="#">' . get_the_title($page->ID) . '</a> » ';
            $parent_id = $page->post_parent;

        $breadcrumbs = array_reverse($breadcrumbs);
        foreach($breadcrumbs as $crumb) $trail .= $crumb;

    $trail .= '<a href="#">' . 'Home' . '</a> ' . '<a href="' . $url . '">' . $page_title . '</a>';     
    $trail .= '';

    return $trail;  
add_shortcode('breadcrumbs', 'get_breadcrumb');

In the custom post-type template file, I have pulled in a page template using a shortcode to the plug-in extension Templatera. This plug-in allowed me to create the page template with the wpbakery builder and then link it to the custom post-type template file.

Below is the shortcode which pulls in the template in the custom post-type template file.

<?php echo do_shortcode('[templatera id="254"]'); ?>

Here is a link to one of the posts so that you are able to see it is displaying the shortcode template name rather than the actual post name:

Any help would be appreciated. Thanks in advance.

Jordan Kellet 2 months 2022-10-13T10:43:16-05:00 0 Answers 0 views 0

Leave an answer