Viewing 8 replies - 1 through 8 (of 8 total)
  • Theme Author Tom

    (@edge22)

    Breadcrumbs aren’t built into the theme, but you can easily integrate breadcrumbs into it.

    For example, WordPress SEO has a breadcrumbs feature, which you can add to the theme in two ways:

    1. The GP Hooks addon – simply paste the breadcrumbs PHP function into your desired hook (Before Content most likely), click execute PHP and you’re done.

    2. With a PHP function in a child theme. Which would look something like this: https://gist.github.com/generatepress/a13fbd2bb88008da572f

    To get the breadcrumbs code, go to “SEO > Internal Links”, and you’ll find it at the bottom.

    This same method can be used with any third-party breadcrumb plugin that offers PHP code.

    Let me know if this helps or not,
    Tom

    Theme Author Tom

    (@edge22)

    Hi there,

    Were you able to add the breadcrumbs to the theme?

    Let me know ??
    Tom

    Thread Starter redthruviolet

    (@redthruviolet)

    Yes, breadcrumbs have been added.

    You can see them here:

    https://www.sustainablemontereycounty.com/likeweebly/

    In the child theme header.php file, after “<?php do_action( ‘generate_after_header’ ); ?>”, I put this code:

    <div class=”grid-container grid-parent”>
    <?php the_breadcrumb(); ?>
    </div>

    Here is the breadcrumb code, which, unfortunately I had to place in the parent theme’s functions.php file (this seems to be the only outstanding issue):

    function the_breadcrumb()
    {
    global $post;

    /* Check for Front Page */

    if (is_front_page())
    {
    echo ‘<p id=”breadcrumbs”> You are Here:   <a href=”‘;
    echo get_option(‘home’);
    echo ‘”>‘;
    echo ‘Home’;
    echo ‘
    </p>’;
    }

    else

    {

    /* Show Breadcrumbs */

    echo ‘<ul id=”breadcrumbs”>’;

    echo ‘

    • You are Here:   <a href=”‘;
      echo get_option(‘home’);
      echo ‘”>’;
      echo ‘Home’;
      echo ‘
    • <li class=”separator”> > ‘;

      if( is_home() && get_option(‘page_for_posts’) )
      {
      /* echo ‘‘; */
      echo ‘‘ . apply_filters(‘the_title’,get_page( get_option(‘page_for_posts’) )->post_title) . ‘‘;
      /* echo ‘
      ‘; */
      }

      if (is_category() || is_single())
      {
      echo ‘

    • ‘;
      the_category(‘
    • <li class=”separator”> >

    • ‘);
    • if (is_single())
      {
      echo ‘
      <li class=”separator”> >

    • ‘;
      the_title();
      echo ‘
    • ‘;
      }
      }

      elseif (is_page())

      {

      if($post->post_parent)
      {
      $anc = get_post_ancestors( $post->ID );
      $anc_count = count($anc);
      // echo “
      anc_count = ” . $anc_count;

      $title = get_the_title();

      /* Go backwards through the array, to get the correct path display */

      for ($k=$anc_count; $k>0; $k=$k-1)
      {
      $ancestor = $anc[$k-1];
      $output = ‘

    • ‘.get_the_title($ancestor).’
    • <li class=”separator”> > ‘;
      echo $output;

      }

      echo ‘

    • <strong title=”‘.$title.'”> ‘.$title. ‘
    • ‘;
      }

      else

      {
      echo ‘

    • ‘ .get_the_title(). ‘
    • ‘;
      }

      }

      elseif (is_tag()) {single_tag_title();}
      elseif (is_day()) {echo”

    • Archive for “; the_time(‘F jS, Y’); echo’
    • ‘;}
      elseif (is_month()) {echo”

    • Archive for “; the_time(‘F, Y’); echo’
    • ‘;}
      elseif (is_year()) {echo”

    • Archive for “; the_time(‘Y’); echo’
    • ‘;}
      elseif (is_author()) {echo”

    • Author Archive”; echo’
    • ‘;}
      elseif (isset($_GET[‘paged’]) && !empty($_GET[‘paged’])) {echo ”

    • Blog Archives”; echo’
    • ‘;}
      elseif (is_search()) {echo”

    • Search Results”; echo’
    • ‘;}

      echo ”;

      }
      }

    Theme Author Tom

    (@edge22)

    You can put that function in the child theme’s functions.php file instead of the parent theme’s functions.php file – it will work the same.

    Then you can hook it into the header instead of editing that file, like this:

    add_action('generate_after_header','custom_add_breadcrumbs');
    function custom_add_breadcrumbs() { ?>
         <div class="grid-container grid-parent">
               <?php the_breadcrumb(); ?>
         </div>
    <?php }

    That would also go in the child theme’s functions.php file.

    Thread Starter redthruviolet

    (@redthruviolet)

    Well, I tried some of that.
    I copied functions.php to the child theme folder, and added the function there.
    Then, when I launched the site, there were error messages saying you cannot redeclare a function.

    Theme Author Tom

    (@edge22)

    The functions file should be empty except for your new function.

    The whole file looks like this:

    <?php
    add_action('generate_after_header','custom_add_breadcrumbs');
    function custom_add_breadcrumbs() { ?>
         <div class="grid-container grid-parent">
               <?php the_breadcrumb(); ?>
         </div>
    <?php }
    
    function the_breadcrumb()
    {
    
    ... The rest of the_breadcrumb function
    
    }

    There’s no need to copy the functions over from the parent’s functions.php file – those functions are included anyways.

    Thread Starter redthruviolet

    (@redthruviolet)

    Well, thank you so much!
    That worked.

    Theme Author Tom

    (@edge22)

    You’re very welcome.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Adding Breadcrumbs’ is closed to new replies.