So the Yoast SEO plugin provides some handy stuff within WordPress, one of these is the Breadcrumb functionality, however the markup output is within span tags (I added # for URLs – don’t worry about that)…
<span xmlns:v="http://rdf.data-vocabulary.org/#">
<span typeof="v:Breadcrumb">
<a property="v:title" rel="v:url" href="#">Home</a>
</span>
<span typeof="v:Breadcrumb">
<a property="v:title" rel="v:url" href="#">Our Services</a>
</span>
<span typeof="v:Breadcrumb">
<a property="v:title" rel="v:url" href="#">GP Services</a>
</span>
<span typeof="v:Breadcrumb">
<span property="v:title" class="breadcrumb_last">GP Appointments</span>
</span>
</span>
I’d like to output the breadrcumbs as a list instead of these spans – so ultimately I think I need to add some sort of filter to my functions.php file – so when I update the Yoast SEO plugin down the line it doesn’t overwrite my edits.
Within “/plugins/wordpress-seo/frontend/class-breadcrumbs.php” there is some code at the start where you can set the wrapper of the element.
Currently (minus comments and unrelated bits of code):
if ( ! class_exists( 'WPSEO_Breadcrumbs' ) ) {
class WPSEO_Breadcrumbs {
private $element = 'span';
So this is the part I need to overwrite with something in my theme’s functions.php file.
I’m struggling with the markup for how to do this however.
There also seems to be a filter in this plugin file too:
private function filter_wrapper() {
$wrapper = apply_filters( 'wpseo_breadcrumb_output_wrapper', $this->wrapper );
$wrapper = tag_escape( $wrapper );
if ( is_string( $wrapper ) && '' !== $wrapper ) {
$this->wrapper = $wrapper;
}
}
Any help would be greatly appreciated.
I believe I found a solution — my execution:
functions.php
Then I call
get_breadcrumb()
wherever I need it in the theme.Then in yoast settings, set the “separator between breadcrumbs” option to:
resulting code should end up like this:
I didn’t find a simple way to do this, so I ended up just altering my CSS styles to account for the fact that instead of an unordered list, the elements were nested spans and links – not the end of the world, and a solution of sorts, but not really the solution I had in mind, sadly.
I’m sure there’s a way to do this – but without help, I’m struggling.