Hey guys,
I am scratching my head over here… I have the following as a custom function but for some unknown reason it is not executing. I’ve linted the PHP to check for syntax errors. I can’t find any. Any help is greatly appreciated!
In lib/extras.php:
/**
* Custom Breadcrumbs
*/
function custom_breadcrumb() {
global $post;
$title = get_the_title();
$url = site_url('/newsevents/');
echo '<ol class="breadcrumb">';
if (!is_front_page()) {
echo '<li><a href="';
echo get_option('home');
echo '">';
echo 'Home';
echo '</a></li>';
if (is_home() || is_blog() ) {
echo '<li>';
echo '</li><a href="';
echo $url;
echo '">News</a><li>';
if (is_single()) {
echo '</li><li>';
the_title();
echo '</li>';
}
} elseif (is_page()) {
if($post->post_parent){
$anc = get_post_ancestors( $post->ID );
$title = get_the_title();
foreach ( $anc as $ancestor ) {
$output = '<li><a href="'.get_permalink($ancestor).'" title="'.get_the_title($ancestor).'">'.get_the_title($ancestor).'</a></li>';
}
echo $output;
echo $title;
} else {
echo '<li>'.get_the_title().'</li>';
}
}
}
elseif (is_tag()) {single_tag_title();}
elseif (is_day()) {echo"<li>Archive for "; the_time('F jS, Y'); echo'</li>';}
elseif (is_month()) {echo"<li>Archive for "; the_time('F, Y'); echo'</li>';}
elseif (is_year()) {echo"<li>Archive for "; the_time('Y'); echo'</li>';}
elseif (is_author()) {echo"<li>Author Archive"; echo'</li>';}
elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {echo "<li>Blog Archives"; echo'</li>';}
elseif (is_search()) {echo"<li>Search Results"; echo'</li>';}
echo '</ol>';
}
add_filter('custom_breadcrumb', __NAMESPACE__ . '\\custom_breadcrumb');
In my template file:
<?php
if ( function_exists('custom_breadcrumb') && !is_front_page() ) {
custom_breadcrumb();
} ?>