Breadcrumbs don't link to the current post/page but a forum member wanted to make a link. It was an irresistible challenge.
A member of the Genesis WordPress Facebook group asked about making the page title a link in Genesis breadcrumbs:
Using Genesis Breadcrumbs, how do I make the page title into a link, linking to the same page rather than just being text?
One of the first replies to the question was another question – why? It’s a valid question because linking a page/post to itself is pointless. The member said that he was building a “weird silo thing”. Whatever the reason, I spent a little bit of time reading the Genesis breadcrumb code and developing a short solution.
Reading the Genesis breadcrumbs code
I enabled breadcrumbs on posts page, single posts, pages and archives and reloaded the site.
I viewed a page that has a parent page. There’s quite a bit of markup in the breadcrumbs:
I wanted to avoid hard coding the markup in my plugin code but the function that generates the markup is a member function of the Genesis_Breadcrumbs class. I chose not to create a new instance of the class to access that function as I didn’t want to overly complicate the code. So, I just copied the markup for the parent page.
The filter function is given the full markup, including the unlinked page at the end. I used strrpos() to search for the unlinked page title from the end and replace it with breadcrumb markup for the page. strpos() returns the position of the string and I pass this position to substr_replace() to inject the markup in the right place.
Leave a Reply