Manual workaround to correct breadcrumb structure

Hi

Please see previous thread for messages containing my issue with some fixes implemented as advised by your colleague but unfortunatley they are not working.

Recap of issue:

I just noticed that my article is not nested under my blog URL: klineadventures.com/blog/
Instead, I see that it is not nested: https://klineadventures.com/gulmarg-gondola-claims-7-lives/2
It should be nested as such: https://klineadventures.com/blog/gulmarg-gondola-claims-7-lives/1
Can this be corrected manually, if so how?

Paul

Hello There,

Thanks for writing in!

As what Lely mentioned that if you assign the “Blog” pages as you Posts Page in Settings > Reading >
Front page displays (http://prntscr.com/fqmgig), you will have the blog slug in your breadcrumb just as shown here: https://prnt.sc/fqmgal

There is no code to modify just assign a page as your Post Page so that you will have the blog trail in your breadcrumb.

Hope this helps.

Hi RueNel,

A little confused…

  1. I was provided the below code to modify by your colleague see below do I still need to use it?

Hi @paullalley,

1.) Not yet but I can add this as feature request so this can be taken into consideration. All of these items are discussed with our team internally and prioritized based on the amount of interest a particular feature might receive.
2.) A workaround is to add the actual blog page on the breadcrumb functions manually. Add this code on your child theme functions.php file:

// Breadcrumbs
// =============================================================================
if ( ! function_exists( ‘x_breadcrumbs’ ) ) :
function x_breadcrumbs() {

if ( x_get_option( ‘x_breadcrumb_display’ ) ) {

GLOBAL $post;

$is_ltr = ! is_rtl();
$stack = x_get_stack();
$delimiter = x_get_breadcrumb_delimiter();
$home_text = x_get_breadcrumb_home_text();
$home_link = home_url();
$current_before = x_get_breadcrumb_current_before();
$current_after = x_get_breadcrumb_current_after();
$page_title = get_the_title();
$blog_title = get_the_title( get_option( ‘page_for_posts’, true ) );

if ( ! is_404() ) {
$post_parent = $post->post_parent;
} else {
$post_parent = ‘’;
}

if ( X_WOOCOMMERCE_IS_ACTIVE ) {
$shop_url = x_get_shop_link();
$shop_title = x_get_option( ‘x_’ . $stack . ‘_shop_title’ );
$shop_link = ‘’ . $shop_title . ‘’;
}

echo ‘

’ . $home_text . ‘’ . $delimiter;
if ( is_home() ) {

  echo $current_before . $blog_title . $current_after;

} elseif ( is_category() ) {

  $the_cat = get_category( get_query_var( 'cat' ), false );
  if ( $the_cat->parent != 0 ) echo get_category_parents( $the_cat->parent, TRUE, $delimiter );
  echo $current_before . single_cat_title( '', false ) . $current_after;

} elseif ( x_is_product_category() ) {

  if ( $is_ltr ) {
    echo $shop_link . $delimiter . $current_before . single_cat_title( '', false ) . $current_after;
  } else {
    echo $current_before . single_cat_title( '', false ) . $current_after . $delimiter . $shop_link;
  }

} elseif ( x_is_product_tag() ) {

  if ( $is_ltr ) {
    echo $shop_link . $delimiter . $current_before . single_tag_title( '', false ) . $current_after;
  } else {
    echo $current_before . single_tag_title( '', false ) . $current_after . $delimiter . $shop_link;
  }

} elseif ( is_search() ) {

  echo $current_before . __( 'Search Results for ', '__x__' ) . '“' . get_search_query() . '”' . $current_after;

} elseif ( is_singular( 'post' ) ) {

  if ( get_option( 'page_for_posts' ) == is_front_page() ) {
    echo $current_before . $page_title . $current_after;
  } else {
    if ( $is_ltr ) {
      echo '<a href="https://klineadventures.com/blog/"> BLOG </a>' . $delimiter . $current_before . $page_title . $current_after;
    } else {
      echo $current_before . $page_title . $current_after . $delimiter . '<a href="' . get_permalink( get_option( 'page_for_posts' ) ) . '">' . $blog_title . '</a>';
    }
  }

} elseif ( x_is_portfolio() ) {

  echo $current_before . get_the_title() . $current_after;

} elseif ( x_is_portfolio_item() ) {

  $link  = x_get_parent_portfolio_link();
  $title = x_get_parent_portfolio_title();

  if ( $is_ltr ) {
    echo '<a href="' . $link . '">' . $title . '</a>' . $delimiter . $current_before . $page_title . $current_after;
  } else {
    echo $current_before . $page_title . $current_after . $delimiter . '<a href="' . $link . '">' . $title . '</a>';
  }

} elseif ( x_is_product() ) {

  if ( $is_ltr ) {
    echo $shop_link . $delimiter . $current_before . $page_title . $current_after;
  } else {
    echo $current_before . $page_title . $current_after . $delimiter . $shop_link;
  }

} elseif ( x_is_buddypress() ) {

  if ( bp_is_group() ) {
    echo '<a href="' . bp_get_groups_directory_permalink() . '">' . x_get_option( 'x_buddypress_groups_title' ) . '</a>' . $delimiter . $current_before . x_buddypress_get_the_title() . $current_after;
  } elseif ( bp_is_user() ) {
    echo '<a href="' . bp_get_members_directory_permalink() . '">' . x_get_option( 'x_buddypress_members_title' ) . '</a>' . $delimiter . $current_before . x_buddypress_get_the_title() . $current_after;
  } else {
    echo $current_before . x_buddypress_get_the_title() . $current_after;
  }

} elseif ( x_is_bbpress() ) {

  remove_filter( 'bbp_no_breadcrumb', '__return_true' );

  if ( bbp_is_forum_archive() ) {
    echo $current_before . bbp_get_forum_archive_title() . $current_after;
  } else {
    echo bbp_get_breadcrumb();
  }

  add_filter( 'bbp_no_breadcrumb', '__return_true' );

} elseif ( is_page() && ! $post_parent ) {

  echo $current_before . $page_title . $current_after;

} elseif ( is_page() && $post_parent ) {

  $parent_id   = $post_parent;
  $breadcrumbs = array();

  if ( is_rtl() ) {
    echo $current_before . $page_title . $current_after . $delimiter;
  }

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

  if ( $is_ltr ) {
    $breadcrumbs = array_reverse( $breadcrumbs );
  }

  for ( $i = 0; $i < count( $breadcrumbs ); $i++ ) {
    echo $breadcrumbs[$i];
    if ( $i != count( $breadcrumbs ) -1 ) echo $delimiter;
  }

  if ( $is_ltr ) {
    echo $delimiter . $current_before . $page_title . $current_after;
  }

} elseif ( is_tag() ) {

  echo $current_before . single_tag_title( '', false ) . $current_after;

} elseif ( is_author() ) {

  GLOBAL $author;
  $userdata = get_userdata( $author );
  echo $current_before . __( 'Posts by ', '__x__' ) . '&#8220;' . $userdata->display_name . $current_after . '&#8221;';

} elseif ( is_404() ) {

  echo $current_before . __( '404 (Page Not Found)', '__x__' ) . $current_after;

} elseif ( is_archive() ) {

  if ( x_is_shop() ) {
    echo $current_before . $shop_title . $current_after;
  } else {
    echo $current_before . __( 'Archives ', '__x__' ) . $current_after;
  }

}

echo ‘

’;

}

}
endif;
You can see that I have updated this part under the single post filter:
echo ‘’ . $blog_title . ‘’ . $delimiter . $current_before . $page_title . $current_after;
To this:
echo ’ BLOG ’ . $delimiter . $current_before . $page_title . $current_after;


Please confirm what I need to do.

Paul.

Please also note that I did update the “Reading” settings as you articulated and it does change the blog articles breadcrumbs. However the main layout it is giving me now for the blog page seems to be pulling a new template… see attacehd:

It seems to be loading a different page template, how do I fix this?

Please note that I have removed my changes in order for you to review again.

Paul.

Hi Paul,

Thanks for updating in! You will have two choices here:
1.) If you assign the Blog page as your post page, the breadcrumb will be corrected and your blog page will look like the one from your screenshot because WordPress will take over generating the post items using the masonry layout. Please also notice that you have page navigation.

2.) If you do not want the result in #1, you will make use of the code as suggested by our colleague and manually add “blog” in the breadcrumb. In your blog page will display like what you have designed in Cornerstone and you will not have pagination.

What should be the final output you want to display so that we can proceed with the resolution of this issue?

Thank you in advance.

Option 2 is preferable. Please note that I already tried to implement option 2 in the pro child theme with no result. Can you take a look please and tell me again how to do it as I would also like to implement this solution on a couple of other pages that have a similar issue.

Thanks in advance!

P.

Hi Paul,

We’re sorry for the confusion. The code will only work on X theme and not Pro. Breadcrumbs as of now is not yet available on PRO since it is part of the header. We have plans on adding Breadcrumbs element on the header builder. We will let you know once this is available. We just can’t promise an ETA.

Hi @Lely,

I understand breadcrumbs are not working in the Pro header. However, if that is the case, how was I able to call them in on each page? This makes no sense at all… As you can see, I’m simply calling them in at the moment with some PHP. I don’t understand if I can get them to show why can’t I do a minimal fix on a specific page to display as desired?

Paul.

Hi Paul,

Please set your Blog page as your Posts page under Settings > Reading and your breadcrumbs code will work.

Thanks

Hi @paul.ravena,

Correct, this works, however, the issue is that the blog page template then changes breaking the existing design using the grid as per my previous screenshot.

Paul.

Hi Paul,

I can see how you add it as a shortcode. It should work. Please try clearing cache.We might be seeing a cache content on the frontend.

@Lely, I am confused…

  1. Did you implement a fix? if so what?
  2. Do you want me to clear the site cache in WP backend? I cleared my browser cache with no change…

P.

Hi Paul,

I didn’t edit anything because your current code should work. I tried it on my test site. Just clear WP backend cache so we can make sure that we are not seeing a cache content.

@Lely,

Cached cleared and the breadcrumb structure still looks the same as before. Please see my screenshot attached.

The breadcrumbs I inserted through shortcode are being called in. However, as per my original message they are not displaying the correct structure

Current Structure: HOME > POST TITLE
Correct Structure: HOME > BLOG > POST TITLE

Thanks,
P.

Hi,

I went ahead and fix it by change this line code that reads.

 if ( get_option( 'page_for_posts' ) == is_front_page() ) {
            echo $current_before . $page_title . $current_after;
          } else {
           if ( $is_ltr ) {
          echo '<a href="https://klineadventures.com/blog/"> BLOG </a>' . $delimiter . $current_before . $page_title . $current_after;
        } else {
          echo $current_before . $page_title . $current_after . $delimiter . '<a href="' . get_permalink( get_option( 'page_for_posts' ) ) . '">' . $blog_title . '</a>';
        }
          }

with this

if ( $is_ltr ) {
          echo '<a href="https://klineadventures.com/blog/"> BLOG </a>' . $delimiter . $current_before . $page_title . $current_after;
        } else {
          echo $current_before . $page_title . $current_after . $delimiter . '<a href="' . get_permalink( get_option( 'page_for_posts' ) ) . '">' . $blog_title . '</a>';
        }

Kindly check in your end.

Brilliant, this works perfectly!

How do I do this on 2 other pages as they have the same problem:


Was this code put in the child theme?

Thanks in advance.

Paul.

I also just noticed that the URL structure is not being corrected to reflect the breadcrumb?

P.

Hello There,

Thanks for updating in!

https://klineadventures.com/our-team/catherine-chan/
https://klineadventures.com/adventure/ski-in-gulmarg/

These pages are of different custom post type. These are not posts so you will need another line of code. As this is all custom development, regretfully we won’t be able to assist further. Custom development is outside the scope of our support. We’re happy to provide advice and get you started in the right direction, but you would still be responsible for the implementation.

Regarding the url, please keep in mind that the breadcrumb and the url are two separate things. The URL is controlled by the Permalinks in the settings, Settings > Permalinks. The breadcrumb on the other hand is by the custom code which you are trying to customized.

Hope this helps.

Thanks. As I previously asked, where was the code inserted? Child theme and which file?

P.

Hello There,

The breadcrumbs code provided by Lely from this thread: https://theme.co/apex/forum/t/breadcrumbs-for-custom-post-type/487/4 should be added in your child theme’s functions.php file.

Hope this helps.