Skip to content

Instantly share code, notes, and snippets.

@bmoredrew
Forked from doubleedesign/breadcrumbs-list.php
Created August 26, 2022 20:23
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 bmoredrew/9aa1add9cb811b1a8aba98dfbcb45b71 to your computer and use it in GitHub Desktop.
Save bmoredrew/9aa1add9cb811b1a8aba98dfbcb45b71 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