Wordpress Generate Breadcrumb - PHP

Wordpress Generate Breadcrumb - PHP

code snippet

php
function the_breadcrumb() {
	$delimiter = '<span>/</span>';
        $currentBefore = '<li class="current">';
        $currentAfter = '</li>';
        
        if ( !is_home() && !is_front_page() || is_paged() ) {
            echo '<ul class="nav-header">';
            /* Homepage */
            echo '<li><a href="';
            echo get_option('home');
            echo '">Home</a></li>';
            echo ' ' . $delimiter . ' ';
            global $post;
            
            if ( is_page() && !$post->post_parent ){
                /* current page */
                echo $currentBefore;
                the_title();
                echo $currentAfter;
            }
            elseif ( is_page() && $post->post_parent ){
                /* parent pages*/
                $parent_id  = $post->post_parent;
                $breadcrumbs = array();
                while ($parent_id) {
                  $page = get_page($parent_id);
                  $breadcrumbs[] = '<li><a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a></li>';
                  $parent_id  = $page->post_parent;
                }
                $breadcrumbs = array_reverse($breadcrumbs);
                foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
                echo $currentBefore;
                the_title();
                echo $currentAfter;
            }
          echo '</ul>';
        }
}

"It is never too late to be what you might have been"

Contact me!

Have questions? Feel free to use the form or send me an email with any questions.

I will be responsive to your requests and your questions.