Powered by Blogger.

Custom Breadcrumb in wordpress with parent link and with grandparent link

 



This blog will short out your search related to wordpress breadcrumb and save yout time to find the solution for that issue. We will provide a best idea or solution for custom breadcrumb that is 100% tested code by our wordpress teams and give a best result that will help you to avoid unnecessary installing wordpress breadcrumb plugin for small things.
The following code will display the links to the ancestors by working out how far away the current page is from the home page and displaying the necessary parent and grandparent links accordingly.


Php Code
	
    
	
    <div class="bread-crumb">
       <?php 
        $parent = get_post($post->post_parent);
        $parent_title = get_the_title($parent);
        $grandparent = $parent->post_parent;
        $grandparent_title = get_the_title($grandparent); ?>
        <a href="<?php echo esc_url( home_url( '/' ) ); ?>">Home</a>
        <?php 
        if ($grandparent == is_page('0')) { ?>
        | <a href="/<?php echo get_permalink($grandparent); ?>"> 
        <?php echo $grandparent_title; ?></a>
        | <a href="<?php echo get_permalink($post->post_parent); ?>">
        <?php echo $parent_title; ?></a>
    
        <?php 
        } elseif ($post->post_parent ==is_page('0')) {?>
        | <a href="<?php echo get_permalink($post->post_parent) ?>"> 
        <?php echo $parent_title; ?></a>
    
        <?php // I must be a top level page!
        } else { ?> 
    
        <?php }?>| <?php echo the_title(); ?>
    </div>
    

No comments