I want to customise the output of Yoast SEO breadcrumbs, I have this so far which works great:
add_filter( 'wpseo_breadcrumb_single_link', 'ss_breadcrumb_single_link', 10, 2 );
function ss_breadcrumb_single_link( $link_output, $link ) {
$element = 'li';
$element = esc_attr( apply_filters( 'wpseo_breadcrumb_single_link_wrapper', $element ) );
$link_output = '<' . $element . ' typeof="v:Breadcrumb">';
if ( isset( $link['url'] ) && ( $i < ( count( $links ) - 1 ) || $paged ) ) {
$link_output .= '<a href="' . esc_url( $link['url'] ) . '" rel="v:url" property="v:title">' . esc_html( $link['text'] ) . '</a>';
} else {
if ( isset( $opt['breadcrumbs-boldlast'] ) && $opt['breadcrumbs-boldlast'] ) {
$link_output .= '<strong class="breadcrumb_last" property="v:title">' . esc_html( $link['text'] ) . '</strong>';
} else {
$link_output .= '<li class="breadcrumb_last" property="v:title">' . esc_html( $link['text'] ) . '</li>';
}
}
$link_output .= '</' . $element . '>';
return $link_output;
}
add_filter( 'wpseo_breadcrumb_output_wrapper', 'ss_breadcrumb_output_wrapper', 10, 1 );
function ss_breadcrumb_output_wrapper( $wrapper ) {
$wrapper = 'ol';
return $wrapper;
}
Next step is to change this line:
return apply_filters( 'wpseo_breadcrumb_output', '<' . $wrapper . $id . $class . ' xmlns:v="http://rdf.data-vocabulary.org/#">' . $output . '</' . $wrapper . '>' );
I want to add an aria element of aria-labelledby="breadcrumblabel"
to that output. So I setup this function:
add_filter( 'wpseo_breadcrumb_output', 'ss_breadcrumb_output' );
function ss_breadcrumb_output() {
return apply_filters( 'ss_breadcrumb_output', '<' . $wrapper . $id . $class . ' xmlns:v="http://rdf.data-vocabulary.org/#">' . $output . '</' . $wrapper . '>' );
}
Problem I am having is $wrapper $id $class
and $output
all return null. I think I know why they are null although as a PHP beginner I can't explain it.
If someone could point me in thr right direction so I can go figure this out, i'd appreciate it.
Thanks.