'; // tag before the current breadcrumb.
$after = ''; // tag after the current breadcrumb.
$home_link = home_url( '/' );
echo '
';
echo '- ' . esc_html__( 'Home', 'bogaty-lite' ) . '
' ;
if ( is_home() ) {
echo '- ' . get_query_var( 'pagename' ) . '
'; // WPCS: XSS OK.
}
// Handle the category.
if ( is_category() ) {
$this_cat = get_category( get_query_var( 'cat' ), false );
if ( 0 !== $this_cat->parent ) {
echo get_category_parents( $this_cat->parent, true, ' ' ); // WPCS: XSS OK.
} else {
echo $before . $this_cat->name . $after; // WPCS: XSS OK.
}
} elseif ( is_search() ) {
echo $before . 'Search results for "' . get_search_query() . '"' . $after; // WPCS: XSS OK.
} elseif ( is_day() ) { // Handle the time.
echo '- ' . get_the_time( 'Y' ) . '
' ; // WPCS: XSS OK.
echo '- ' . get_the_time( 'F' ) . '
' ; // WPCS: XSS OK.
echo $before . get_the_time( 'd' ) . $after; // WPCS: XSS OK.
} elseif ( is_month() ) {
echo '- ' . get_the_time( 'Y' ) . '
' ; // WPCS: XSS OK.
echo $before . get_the_time( 'F' ) . $after; // WPCS: XSS OK.
} elseif ( is_year() ) {
echo $before . get_the_time( 'Y' ) . $after; // WPCS: XSS OK.
} elseif ( is_single() ) { // Handle the single with categories.
// Show the name of jetpack post type or another post types, followed by the title of the post of that post type.
if ( get_post_type() !== 'post' ) {
$post_type = get_post_type_object( get_post_type() );
$slug = $post_type->rewrite;
echo '- ' . $post_type->labels->singular_name . '
'; // WPCS: XSS OK.
esc_html( the_title( $before, $after ) );
} else {
echo '- ' . get_the_category_list( ', ' ) . '
'; // WPCS: XSS OK.
esc_html( the_title( $before, $after ) );
}
} elseif ( ! is_single() && ! is_page() && get_post_type() !== 'post' && ! is_404() ) {
$post_type = get_post_type_object( get_post_type() );
echo $before . $post_type->labels->singular_name . $after; // WPCS: XSS OK.
}
// Handle the page.
$id = get_the_id();
$parent_id = wp_get_post_parent_id( $id );
// Check if page has parent.
if ( is_page() && ! $parent_id ) {
esc_html( the_title( $before, $after ) );
}
// If the page has parent.
if ( is_page() && $parent_id ) {
$breadcrumbs = array();
// Get all the parents of the child page. The page of parent is set in the page not in the menu.
while ( $parent_id ) {
$page = get_post( $parent_id );
$breadcrumbs[] = '- ' . get_the_title( $page->ID ) . '
';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse( $breadcrumbs );
$parent_length = count( $breadcrumbs );
$i = 0;
while ( $i < $parent_length ) {
echo $breadcrumbs[ $i ]; // WPCS: XSS OK.
$i++;
}
esc_html( the_title( $before, $after ) );
} elseif ( is_tag() ) {
echo $before . single_tag_title( '', false ) . $after; // WPCS: XSS OK.
} elseif ( is_author() ) {
global $author;
$userdata = get_userdata( $author );
echo $before . $userdata->display_name . $after; // WPCS: XSS OK.
} elseif ( is_404() ) {
echo $before . esc_html__( 'Error 404', 'bogaty-lite' ) . $after; // WPCS: XSS OK.
}
echo '
';
} // End if().
}
} // End if().