Skip to content

Instantly share code, notes, and snippets.

@jessedmatlock
Last active March 17, 2021 16:32
Show Gist options
  • Save jessedmatlock/31be50d3da86de516c4682bb39706490 to your computer and use it in GitHub Desktop.
Save jessedmatlock/31be50d3da86de516c4682bb39706490 to your computer and use it in GitHub Desktop.
/*
* Filter the output of Yoast breadcrumbs so each item is an <li> with schema markup
* @param $link_output
* @param $link
* @return string
*/
function revive_update_yoast_breacrumbs( $link_output, $link ) {
$updated_output = '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">';
$updated_output .= '<a itemprop="item" href="' . $link['url'] . '" itemprop="url">' . $link['text'] . '</a>';
// working on insert position of item within breadscrumbs
// $updated_output .= '<meta itemprop="position" content="1" />';
$updated_output .= '</li>';
return $updated_output;
}
add_filter( 'wpseo_breadcrumb_single_link', 'revive_update_yoast_breacrumbs', 10, 2 );
/*
* Filter the output of Yoast breadcrumbs to remove <span> tags added by the plugin
* @param $output
* @return mixed
*/
function revive_clean_yoast_breadcrumb_output( $output ){
$start = '<span>';
$end = '</span>';
$output = str_replace( $start, $end, $output );
return $output;
}
add_filter( 'wpseo_breadcrumb_output', 'revive_clean_yoast_breadcrumb_output' );
function revive_breadcrumbs() {
if ( function_exists('yoast_breadcrumb') ) {
yoast_breadcrumb('<ol class="breadcrumbs-wrapper" itemscope itemtype="https://schema.org/BreadcrumbList">', '</ol>');
}
}
// USE revive_breadcrumbs(); to display breadcrumbs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment