In the members-only forum, a user asked:
Hi Sridhar,
I wonder if it’s possible to change the genesis breadcrumbs function to use the menu label instead of the page title – (without using a plugin like Yoast or Nexxt Breadcrumbs)?
—
So far, all my searches have come up mostly empty. The only two somewhat useful posts I’ve been able to find are
How to Modify / Customize Genesis Framework Breadcrumbs for your WordPress Blog?(step 4) > and
http://stackoverflow.com/questions/22806170/how-to-get-a-menu-label-via-post-or-page-id
Want to do a tutorial for us? 🙂 > If a menu label has been set, we should use that, if not – just use the page title instead.
By default, the last bit of breadcrumbs on static Pages will show the current Page title.
Let's say you are viewing a static Page titled Contact
and you have added it in your navigation menu. With breadcrumbs enabled for Pages in Genesis theme settings, it's going to appear like this in the front end:
Now if the Navigation Label of the menu item is changed to say, Contact Us
, the breadcrumb will continue to show the Page title.
If you'd like the breadcrumb to also read Contact Us
, the easiest option is to edit the Page and change its title. If for whatever reason you don't want to/can't do that, genesis_page_crumb
filter hook can be used to set the Page breadcrumb to nav menu item label if present, else the default title, including any parent breadcrumbs.
In a custom function hooked to genesis_page_crumb
, we are going to
- define an empty
$menu_item_label
variable. - store the name of the nav menu in a
$menu
variable. - store all menu items of the above navigation menu in a
$nav
array. - for each menu item, check if it points/links to the current Page and if so, set the Page title in
$menu_item_label
variable and break out of the loop. - if
$menu_item_label
is not empty, set it as the crumb else the default.
Add the following in child theme's functions.php
:
To view the full content, please sign up for the membership.
Already a member? Log in below or here.
This is great, but I have one question. How do I make this code apply to the entire array of breadcrumbs? I ask this because I’m working on a site for a client and have a lot of nested pages titled ‘Profile’. In order to make administration easier, I have prefixed the titles of these pages. So, ‘Foo – Profile’, ‘Bar – Profile’, ‘Baz – Profile’, etc. With this code, it now appears as just ‘Profile’. However, when I have a nested page under the profile called ‘Resources’, the breadcrumb appears as ‘Foo – Profile’ -> ‘Resources’. I just want it to say ‘Profile’ -> ‘Resources’. How would I do this?
Try adding this in functions.php: