Created
July 20, 2021 15:33
-
-
Save twobyte/7590b02cdb06da216952ca58f7501039 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function tasty_team_breadcrumb( $crumb, $args ) { | |
// Only modify the breadcrumb if in the correct post type | |
if( $this->post_type !== get_post_type() ) | |
return $crumb; | |
// Grab terms | |
// Primary category support if available. | |
if ( class_exists('WPSEO_Primary_Term') ) | |
{ | |
// Show the post's 'Primary' category, if this Yoast feature is available, & one is set | |
$wpseo_primary_term = new WPSEO_Primary_Term( $this->taxonomies[0], get_the_ID() ); | |
$wpseo_primary_term = $wpseo_primary_term->get_primary_term(); | |
$termObject = get_term( $wpseo_primary_term ); | |
} | |
elseif (function_exists( 'the_seo_framework' )){ | |
$wpseo_primary_term = the_seo_framework()->get_primary_term_id( get_the_ID(), $this->taxonomies[0] ); | |
$termObject = get_term( $wpseo_primary_term ); | |
} | |
if (is_wp_error($termObject) || empty($termObject)) { | |
$terms = get_the_terms( get_the_ID(), $this->taxonomies[0] ); | |
$termObject = array_pop($terms); // we take the first term if they land on this page. | |
} | |
if( empty( $termObject ) || is_wp_error( $termObject ) ){ | |
return $crumb; | |
}else{ | |
// Build the breadcrumb | |
$crumb = '<span class="breadcrumb-link-wrap"><a class="breadcrumb-link" href="' . get_term_link( $termObject, $this->taxonomies[0] ) . '"><span class="breadcrumb-link-text-wrap">' . $termObject->name . '</span></a></span> ' . $args['sep'] . ' ' . get_the_title(); | |
} | |
return $crumb; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment