Skip to content

Instantly share code, notes, and snippets.

@doubleedesign
Created December 4, 2018 00:52
Show Gist options
  • Save doubleedesign/7224a5e990b8506ddb8ec66de8348b2b to your computer and use it in GitHub Desktop.
Save doubleedesign/7224a5e990b8506ddb8ec66de8348b2b 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>');
}
}
@mstudioIL
Copy link

Thanks, the last code
function doublee_breadcrumbs() { if ( function_exists('yoast_breadcrumb') ) { yoast_breadcrumb('<ul>', '</ul>'); } }
need to be in page and not in
It didn't worked in functions.php, the rest of the code is working.
Is there way to change this with functions.php?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment