|
<?php |
|
/* |
|
Plugin Name: Make title a link in Genesis breadcrumbs |
|
Plugin URI: https://www.damiencarbery.com/ |
|
Description: Make page/post/view title a link to itself in Genesis breadcrumbs. Asked in comment for another post. |
|
Author: Damien Carbery |
|
Version: 0.1 |
|
*/ |
|
|
|
add_filter( 'genesis_single_crumb', 'dcwd_last_crumb', 10, 2 ); |
|
add_filter( 'genesis_page_crumb', 'dcwd_last_crumb', 10, 2 ); |
|
add_filter( 'genesis_archive_crumb', 'dcwd_last_crumb', 10, 2 ); |
|
|
|
function dcwd_last_crumb( $crumb, $args ) { |
|
// Get the title and link to the current page/post/view.etc. |
|
if ( is_search() ) { |
|
return $crumb; // Don't handle search pages. |
|
} elseif ( is_404() ) { |
|
return $crumb; // Don't handle 404 pages. |
|
} elseif ( is_page() && ! is_front_page() ) { |
|
$title = get_the_title(); |
|
$crumb_url = get_permalink(); |
|
} elseif ( is_archive() ) { |
|
if ( is_category() ) { |
|
$title = $args['labels']['category'] . single_cat_title( '', false ); |
|
$crumb_url = get_permalink(); |
|
} elseif ( is_tag() ) { |
|
$title = $args['labels']['tag'] . single_term_title( '', false ); |
|
$crumb_url = get_term_link( get_queried_object() ); |
|
} elseif ( is_tax() ) { |
|
//$crumb = $this->get_tax_crumb(); |
|
} elseif ( is_year() ) { |
|
$title = $args[ 'labels' ][ 'date' ] . get_query_var( 'year' ); |
|
$crumb_url = get_year_link( get_query_var( 'year' ) ); |
|
} elseif ( is_month() ) { |
|
$title = $args[ 'labels' ][ 'date' ] . single_month_title( ' ', false ); |
|
$crumb_url = get_month_link( get_query_var( 'year' ), get_query_var( 'month' ) ); |
|
} elseif ( is_day() ) { |
|
$title = $args[ 'labels' ][ 'date' ] . get_query_var( 'day' ) . get_the_date( 'S' ); |
|
$crumb_url = get_day_link( get_query_var( 'year' ), get_query_var( 'month' ), get_query_var( 'day' ) ); |
|
} elseif ( is_author() ) { |
|
$author = get_queried_object(); |
|
$title = $args['labels']['author'] . $author->display_name; |
|
$crumb_url = get_author_posts_url( $author->ID ); |
|
} elseif ( is_post_type_archive() ) { |
|
return $crumb; // Don't handle CPT archives. |
|
} |
|
} elseif ( is_singular() ) { |
|
if ( is_attachment() ) { |
|
return $crumb; // This is actually handled by is_page(). |
|
} elseif ( is_singular( 'post' ) ) { |
|
$title = get_the_title(); |
|
$crumb_url = get_permalink(); |
|
} else { |
|
return $crumb; // Default to not handling. |
|
} |
|
} |
|
|
|
$link = sprintf( '<span class="breadcrumb-link-wrap" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a class="breadcrumb-link" href="%s" itemprop="item"><span class="breadcrumb-link-text-wrap" itemprop="name">%s</span></a></span>', $crumb_url, $title ); |
|
|
|
// Find the page/post title in $crumb and replace it with the link. |
|
$title_position = strrpos( $crumb, $title ); |
|
if ( $title_position !== false ) { |
|
$crumb = substr_replace( $crumb, $link, $title_position, strlen( $title ) ); |
|
} |
|
|
|
return $crumb; |
|
} |