Yoast Breadcrumbs

Hi. I’m trying to use Yoast breadcrumbs with X theme. I found this thread:

RueNel advised this person to use the following code in the child functions.php file:

(I am having trouble formatting it correctly in this thread - I can’t get it all in the box - but you get the idea. You can look at the previously mentioned thread to read it in context.)

if ( ! function_exists( 'x_breadcrumbs' ) ) :
  function x_breadcrumbs() {

    if ( x_get_option( 'x_breadcrumb_display', 1 ) && function_exists('yoast_breadcrumb') ) {
      yoast_breadcrumb('<p id="breadcrumbs">','</p>');
    } else {
      echo '<p>Please install Yoast Breadcrumb plugin.</p>';
    }

  }
endif;

Anyway, I have the pro version of Yoast, and breadcrumbs are enabled. I have also placed this code in the functions.php file of my child theme. However, the Yoast breadcrumbs are not showing up.

Is the recommended code still current, or is there another way to get this to happen? In the Yoast directions, they say to put a snippet of code in the header (but that this may not work with all themes).

I know you don’t do anything beyond a point in the right direction with this kind of thing, but I just want to know if the code given was valid advice. Unfortunately, the person who wrote in never reported back to say whether or not it worked.

Thank you! I really appreciate you guys. :relaxed:

Hi,

I tried that code in my test site and it still works.

Can you try printing some text instead of yoast and see if it works.

eg.


if ( ! function_exists( 'x_breadcrumbs' ) ) :
function x_breadcrumbs() {

if ( x_get_option( 'x_breadcrumb_display', 1 ) && function_exists('yoast_breadcrumb') ) {
   echo "This is a test";
} else {
  echo '<p>Please install Yoast Breadcrumb plugin.</p>';
}
}
endif;

If that doesn’t help, please provide us your wordpress admin login in secure note.

Thanks

It’s encouraging to hear that it worked for you. But it still doesn’t work for me. :frowning:

I’ll send you the credentials in a private note…

Hello @creatorofstuff,

The code should have work in your end as we have tested it before we gave the codes and prevent any errors in the code. I can see that your sites have several out dated plugins. Please have it updated and make sure that it up to date. Also make sure to clear all your plugin cache and site caches too. It is also best that you regenerate the minified JS and CSS in your site. Now after further investigation, the code did not work because you have two x_breadcrumbs() in your child theme.

The first one is:


// ================================================
// Yoast Breadcrumbs
// ================================================

if ( ! function_exists( 'x_breadcrumbs' ) ) :
  function x_breadcrumbs() {

    if ( x_get_option( 'x_breadcrumb_display', 1 ) && function_exists('yoast_breadcrumb') ) {
      yoast_breadcrumb('<p id="breadcrumbs">','</p>');
    } else {
      echo '<p>Please install Yoast Breadcrumb plugin.</p>';
    }

  }
endif;

And the second one is:

// breadcrumbs and addition of cart and wishlist link at top of page
// ============================================================================

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  = '<a href="'. $shop_url .'">' . $shop_title . '</a>';
      }

      echo '<div class="x-breadcrumbs"><a href="' . $home_link . '">' . $home_text . '</a>' . $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="' . get_permalink( get_option( 'page_for_posts' ) ) . '">' . $blog_title . '</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__' ) . '“' . $userdata->display_name . $current_after . '”';

        } 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 '</div>';

    }

  }

You will need to decide which breadcrumb you will use. From that order, the breadcrumb that will display is the custom X theme breadcrumb and not the one from Yoast. You may remove one of the code and the remaining x_breadcrumbs() function will be the one to be displayed in your front end.

Hope this explains everything briefly.

Oh my gosh, you are right! Can you tell I’m not a programmer? :tired_face:

I tried commenting out the second one but then I realized that it also includes showing the icon for the shopping cart and wish list at the top of every page. The result of commenting it out is this:

Sorry to be asking such dumb questions but do you have any advice for me?

Thank you!!! :relaxed:

(And yes, I know some plugins need updating. It always seems like things go wrong when I update so I get nervous to do it. But I will. Promise!)

Hey @creatorofstuff,

You will need to decide which one do you prefer. Are you going to use Yoast Breadcrumbs or just use the theme’s breadcrumbs because I can see that you added some modifications to it. You can not have both by the way.

If I am not mistaken, you have a staging site before. My advice is that, please maintain both the staging and your live site. The staging site will really help you to test run the theme and plugin updates. If there are no errors with the updates in your staging site, then you can proceed the update in the live site. The staging site is helpful and very crucial with updates in order not to broke the live sites. Staging site will help you cope with nervous doing the updates :slight_smile:

Hope this helps.

Yes, I agree. I need to decide, and I have. I’d like to use the Yoast ones because with that I can have the shop show the category before the product name. I honestly don’t remember making modifications to the theme’s breadcrumbs but I believe you! I just wish I knew what was happening with the icons at the top of the page.

I have a test site but for some reason, if I click on products from the test site it always takes me to the live site. Therefore, if an update affects the shop, I won’t know until I update the live site, if that makes sense. So it’s still a little sketchy sometimes.

Thanks anyway. Sorry to bother you. I wish I knew how to fix this.

No problem.
If you need anything else we can help you with, don’t hesitate to open another thread.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.