D
D
Di Da2018-03-04 16:13:41
Layout
Di Da, 2018-03-04 16:13:41

WordPress: How to make a main post category for breadcrumbs?

The problem itself
I will try to explain clearly. So, I have a theme (RedWaves-Lite) with my own breadcrumbs. But here's the problem - the breadcrumbs just show the first one in the list of "selected headings to post". That is, if I choose "Uncategorized, Android, Something else" as headings for the entry, then it shows "Uncategorized" in breadcrumbs.
How I'm supposed to decide
Perhaps you know the Yoast SEO plugin? So here we can select "Main heading". It is used for its (plugin) breadcrumbs. Well, what if we implement a function from Yoast into a theme? That is, set the "Function" of the "Main heading" in the theme code?
What I found in the course of "research"
After 100 failed attempts, I couldn't do it because I don't have enough knowledge. But I found something that might be helpful:

  1. If you remove the breadcrumb code in functions.php, then the entire page disappears
  2. I tried to install HC from Yoast, but the error above does not allow me to do it
Codes from the theme for familiarization
functions.php
/*-----------------------------------------------------------------------------------*/
  /*  Breadcrumbs
  /*-----------------------------------------------------------------------------------*/
  if (!function_exists('redwaves_breadcrumb')) {
    function redwaves_breadcrumb() {
      echo '<div><i class="fa fa-home"></i></div> <div typeof="v:Breadcrumb" class="root"><a rel="v:url" property="v:title" href="';
      echo home_url();
      echo '">'.sprintf( __( "Home","redwaves-lite"));
      echo '</a></div><div>'.__('<i class="fa fa-caret-right"></i>','redwaves-lite').'</div>';
      if (is_category() || is_single()) {
        $categories = get_the_category();
        $output = '';
        if($categories){
          echo '<div typeof="v:Breadcrumb"><a href="'.get_category_link( $categories[0]->term_id ).'" rel="v:url" property="v:title">'.$categories[0]->cat_name.'</a></div><div>'.__('<i class="fa fa-caret-right"></i>','redwaves-lite').'</div>';
        }
        if (is_single()) {
          echo "<div typeof='v:Breadcrumb'><span property='v:title'>";
          the_title();
          echo "</span></div>";
        }
        } elseif (is_page()) {
        echo "<div typeof='v:Breadcrumb'><span property='v:title'>";
        the_title();
        echo "</span></div>";
      }
    }
  }

5a9bf10213362213880036.png
Please help! Is this the case for all topics?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question