Site icon Hip-Hop Website Design and Development

Title and URL Error in Breadcrumb Navigation for Customized Submit Sorts

I’ve this code I obtained from right here on StackOverflow. It really works nice throughout my wordpress website however the issue is that on the customized put up kind single pages, the guardian class’s hyperlink it fetches for each customized put up kind hyperlinks to the present put up itself and never the guardian class hyperlink. Once more, the title it fetches for similar class has some descriptions hooked up to the anchor (title).

For instance: Dwelling > Class: Books > Issues Fall Aside
On this case, after I click on on books, it results in the present web page of issues collapse.

I’ve tried my greatest to work on the code however it’s’nt correcting. The code was posted greater than Two years in the past, please assist me.

    operate get_hansel_and_gretel_breadcrumbs()
{
// Set variables for later use
$here_text        = __( 'You're at the moment right here!' );
$home_link        = home_url('/');
$home_text        = __( 'Dwelling' );
$link_before      = '<span typeof="v:Breadcrumb">';
$link_after       = '</span>';
$link_attr        = ' rel="v:url" property="v:title"';
$hyperlink             = $link_before . '<a' . $link_attr . ' href="%1$s">%2$s</a>' . $link_after;
$delimiter        = ' &raquo; ';              // Delimiter between crumbs
$earlier than           = '<span class="current">'; // Tag earlier than the present crumb
$after            = '</span>';                // Tag after the present crumb
$page_addon       = '';                       // Provides the web page quantity if the question is paged
$breadcrumb_trail = '';
$category_links   = '';
/** 
* Set our personal $wp_the_query variable. Don't use the worldwide variable model on account of 
* reliability
*/
$wp_the_query   = $GLOBALS['wp_the_query'];
$queried_object = $wp_the_query->get_queried_object();
// Deal with single put up requests which incorporates single pages, posts and attatchments
if ( is_singular() ) 
{
/** 
* Set our personal $put up variable. Don't use the worldwide variable model on account of 
* reliability. We'll set $post_object variable to $GLOBALS['wp_the_query']
*/
$post_object = sanitize_post( $queried_object );
// Set variables 
$title          = apply_filters( 'the_title', $post_object->post_title );
$guardian         = $post_object->post_parent;
$post_type      = $post_object->post_type;
$post_id        = $post_object->ID;
$post_link      = $earlier than . $title . $after;
$parent_string  = '';
$post_type_link = '';
if ( 'put up' === $post_type ) 
{
// Get the put up classes
$classes = get_the_category( $post_id );
if ( $classes ) {
// Lets seize the primary class
$class  = $classes[0];
$category_links = get_category_parents( $class, true, $delimiter );
$category_links = str_replace( '<a',   $link_before . '<a' . $link_attr, $category_links );
$category_links = str_replace( '</a>', '</a>' . $link_after,             $category_links );
}
}
if ( !in_array( $post_type, ['post', 'page', 'attachment'] ) )
{
$post_type_object = get_post_type_object( $post_type );
$archive_link     = esc_url( get_post_type_archive_link( $post_type ) );
$post_type_link   = sprintf( $hyperlink, $archive_link, $post_type_object->labels->singular_name );
}
// Get put up mother and father if $guardian !== 0
if ( 0 !== $guardian ) 
{
$parent_links = [];
whereas ( $guardian ) {
$post_parent = get_post( $guardian );
$parent_links[] = sprintf( $hyperlink, esc_url( get_permalink( $post_parent->ID ) ), get_the_title( $post_parent->ID ) );
$guardian = $post_parent->post_parent;
}
$parent_links = array_reverse( $parent_links );
$parent_string = implode( $delimiter, $parent_links );
}
// Lets construct the breadcrumb path
if ( $parent_string ) {
$breadcrumb_trail = $parent_string . $delimiter . $post_link;
} else {
$breadcrumb_trail = $post_link;
}
if ( $post_type_link )
$breadcrumb_trail = $post_type_link . $delimiter . $breadcrumb_trail;
if ( $category_links )
$breadcrumb_trail = $category_links . $breadcrumb_trail;
}
// Deal with archives which incorporates category-, tag-, taxonomy-, date-, customized put up kind archives and writer archives
if( is_archive() )
{
if (    is_category()
|| is_tag()
|| is_tax()
) {
// Set the variables for this part
$term_object        = get_term( $queried_object );
$taxonomy           = $term_object->taxonomy;
$term_id            = $term_object->term_id;
$term_name          = $term_object->title;
$term_parent        = $term_object->guardian;
$taxonomy_object    = get_taxonomy( $taxonomy );
$current_term_link  = $earlier than . $taxonomy_object->labels->singular_name . ': ' . $term_name . $after;
$parent_term_string = '';
if ( 0 !== $term_parent )
{
// Get all the present time period ancestors
$parent_term_links = [];
whereas ( $term_parent ) {
$time period = get_term( $term_parent, $taxonomy );
$parent_term_links[] = sprintf( $hyperlink, esc_url( get_term_link( $time period ) ), $term->title );
$term_parent = $term->guardian;
}
$parent_term_links  = array_reverse( $parent_term_links );
$parent_term_string = implode( $delimiter, $parent_term_links );
}
if ( $parent_term_string ) {
$breadcrumb_trail = $parent_term_string . $delimiter . $current_term_link;
} else {
$breadcrumb_trail = $current_term_link;
}
} elseif ( is_author() ) {
$breadcrumb_trail = __( 'Creator archive for ') .  $earlier than . $queried_object->data->display_name . $after;
} elseif ( is_date() ) {
// Set default variables
$yr     = $wp_the_query->query_vars['year'];
$monthnum = $wp_the_query->query_vars['monthnum'];
$day      = $wp_the_query->query_vars['day'];
// Get the month title if $monthnum has a worth
if ( $monthnum ) {
$date_time  = DateTime::createFromFormat( '!m', $monthnum );
$month_name = $date_time->format( 'F' );
}
if ( is_year() ) {
$breadcrumb_trail = $earlier than . $yr . $after;
} elseif( is_month() ) {
$year_link        = sprintf( $hyperlink, esc_url( get_year_link( $yr ) ), $yr );
$breadcrumb_trail = $year_link . $delimiter . $earlier than . $month_name . $after;
} elseif( is_day() ) {
$year_link        = sprintf( $hyperlink, esc_url( get_year_link( $yr ) ),             $yr       );
$month_link       = sprintf( $hyperlink, esc_url( get_month_link( $yr, $monthnum ) ), $month_name );
$breadcrumb_trail = $year_link . $delimiter . $month_link . $delimiter . $earlier than . $day . $after;
}
} elseif ( is_post_type_archive() ) {
$post_type        = $wp_the_query->query_vars['post_type'];
$post_type_object = get_post_type_object( $post_type );
$breadcrumb_trail = $earlier than . $post_type_object->labels->singular_name . $after;
}
}   
// Deal with the search web page
if ( is_search() ) {
$breadcrumb_trail = __( 'Search question for: ' ) . $earlier than . get_search_query() . $after;
}
// Deal with 404's
if ( is_404() ) {
$breadcrumb_trail = $earlier than . __( 'Error 404' ) . $after;
}
// Deal with paged pages
if ( is_paged() ) {
$current_page = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : get_query_var( 'web page' );
$page_addon   = $earlier than . sprintf( __( ' ( Web page %s )' ), number_format_i18n( $current_page ) ) . $after;
}
$breadcrumb_output_link  = '';
$breadcrumb_output_link .= '<div class="breadcrumb">';
if (    is_home()
|| is_front_page()
) {
// Don't present breadcrumbs on web page considered one of residence and frontpage
if ( is_paged() ) {
$breadcrumb_output_link .= $here_text . $delimiter;
$breadcrumb_output_link .= '<a href="' . $home_link . '">' . $home_text . '</a>';
$breadcrumb_output_link .= $page_addon;
}
} else {
$breadcrumb_output_link .= $here_text . $delimiter;
$breadcrumb_output_link .= '<a href="' . $home_link . '" rel="v:url" property="v:title">' . $home_text . '</a>';
$breadcrumb_output_link .= $delimiter;
$breadcrumb_output_link .= $breadcrumb_trail;
$breadcrumb_output_link .= $page_addon;
}
$breadcrumb_output_link .= '</div><!-- .breadcrumbs -->';
return $breadcrumb_output_link;

}