How to print breadcrumb in wordpress



Here is the steps

First print home page

$base_path = esc_url( home_url( '/' ) ); 
<li class="breadcrumb-item"><a href="<?php print $base_path; ?>">Home</a></li>

then check parent page is available then print parent page

<?php if($post->post_parent){ ?>
 <li class="breadcrumb-item"><a href="<?php  print get_the_permalink( $post->post_parent ); ?>"><?php print get_the_title( $post->post_parent ); ?></a></li>
<?php } ?>

Print current page

<li class="breadcrumb-item"><a href=""><?php the_title(); ?></a></li>

Final Code

$base_path = esc_url( home_url( '/' ) );  

<ol class="breadcrumb">
 <li class="breadcrumb-item"><a href="<?php print $base_path; ?>">Home</a></li>
 <?php if($post->post_parent){ ?>
  <li class="breadcrumb-item"><a href="<?php  print get_the_permalink( $post->post_parent ); ?>"><?php print get_the_title( $post->post_parent ); ?></a></li>
 <?php } ?>
 <li class="breadcrumb-item"><a href=""><?php the_title(); ?></a></li>
</ol>



Related Post


Latest Post


Recent Posts Widget

Make sure to never miss a thing...

Get the latest news from the creative industry along with other creative goodies, conveniently delivered to social media.