Skip to content

Instantly share code, notes, and snippets.

@braddalton
Created May 8, 2019 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save braddalton/58d44e068f0d7c9df466aba3abed954d to your computer and use it in GitHub Desktop.
Save braddalton/58d44e068f0d7c9df466aba3abed954d to your computer and use it in GitHub Desktop.
Yoast SEO Genesis https://wp.me/p1lTu0-ith
protected function get_post_crumb() {
$categories = get_the_category();
$cat_crumb = '';
if ( 1 === count( $categories ) ) {
// If in single category, show it, and any parent categories.
$cat_crumb = $this->get_term_parents( $categories[0]->cat_ID, 'category', true ) . $this->args['sep'];
}
if ( count( $categories ) > 1 ) {
if ( $this->args['heirarchial_categories'] ) {
// Show parent categories - see if one is marked as primary and try to use that.
$primary_category_id = get_post_meta( get_the_ID(), '_category_permalink', true ); // Support for sCategory Permalink plugin.
if ( ! $primary_category_id && function_exists( 'yoast_get_primary_term_id' ) ) {
// Support for Yoast SEO plugin, even if the Yoast Breadcrumb feature is not enabled.
$primary_category_id = yoast_get_primary_term_id();
}
if ( $primary_category_id ) {
$cat_crumb = $this->get_term_parents( $primary_category_id, 'category', true ) . $this->args['sep'];
} else {
$cat_crumb = $this->get_term_parents( $categories[0]->cat_ID, 'category', true ) . $this->args['sep'];
}
} else {
$crumbs = array();
// Don't show parent categories (unless the post happen to be explicitly in them).
foreach ( $categories as $category ) {
$crumbs[] = $this->get_breadcrumb_link(
get_category_link( $category->term_id ),
'',
$category->name
);
}
$cat_crumb = implode( $this->args['list_sep'], $crumbs ) . $this->args['sep'];
}
}
$crumb = $cat_crumb . single_post_title( '', false );
/**
* Filter the Genesis post breadcrumb.
*
* @since 2.5.0
*
* @param string $crumb HTML markup for the post breadcrumb.
* @param array $args Arguments used to generate the breadcrumbs. Documented in Genesis_Breadcrumbs::get_output().
*/
return apply_filters( 'genesis_post_crumb', $crumb, $this->args, $cat_crumb );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment