Skip to content

Instantly share code, notes, and snippets.

@rjekic
Forked from doubleedesign/breadcrumbs-list.php
Created April 11, 2020 15:35
Show Gist options
  • Save rjekic/afc932de7b21dc4863b8fb377edf9c29 to your computer and use it in GitHub Desktop.
Save rjekic/afc932de7b21dc4863b8fb377edf9c29 to your computer and use it in GitHub Desktop.
Mark up Yoast breadcrumbs as an unordered list
<?php
/**
* Filter the output of Yoast breadcrumbs so each item is an <li> with schema markup
* @param $link_output
* @param $link
*
* @return string
*/
function doublee_filter_yoast_breadcrumb_items( $link_output, $link ) {
$new_link_output = '<li itemscope itemtype="http://data-vocabulary.org/Breadcrumb">';
$new_link_output .= '<a href="' . $link['url'] . '" itemprop="url">' . $link['text'] . '</a>';
$new_link_output .= '</li>';
return $new_link_output;
}
add_filter( 'wpseo_breadcrumb_single_link', 'doublee_filter_yoast_breadcrumb_items', 10, 2 );
/**
* Filter the output of Yoast breadcrumbs to remove <span> tags added by the plugin
* @param $output
*
* @return mixed
*/
function doublee_filter_yoast_breadcrumb_output( $output ){
$from = '<span>';
$to = '</span>';
$output = str_replace( $from, $to, $output );
return $output;
}
add_filter( 'wpseo_breadcrumb_output', 'doublee_filter_yoast_breadcrumb_output' );
/**
* Shortcut function to output Yoast breadcrumbs
* wrapped in the appropriate markup
*/
function doublee_breadcrumbs() {
if ( function_exists('yoast_breadcrumb') ) {
yoast_breadcrumb('<ul>', '</ul>');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment