Viewing 3 reply threads
You must be logged in to reply to this topic.
I would like the breadcrumb trail to use the Menu Label versus the Page Title.
I see that breadcrumbs are declared under includes/view/page_header.php. How can I modify this file to accomplish my purpose?
Thank you for your time.
I figured out how to do it so I thought I would post it here for anyone that has a need for this.
I added the following to the chilf theme’s functions.php:
// Show menu label in breadcrumb trail
function get_menu_label_by_post_id($post_id, $menu) {
$menu_title = ”;
$nav = wp_get_nav_menu_items($menu);
foreach ( $nav as $item ) {
if ( $post_id == $item->object_id ) {
$menu_title = $item->post_title;
break;
}
}
return ($menu_title !== ”) ? $menu_title : get_the_title($post_id);
}
After copying includes/view/page_header.php to the child folder, make the following adjustment.
Find:
<li class=”active”>“><?php echo esc_html($title) ?>
and replace with:
<li class=”active”>“><?php echo get_menu_label_by_post_id($post->ID, ‘Main Menu’) ?>
Where ‘Main Menu’ is declared, change this to the menu name being used in Appearance > Menus.
You must be logged in to reply to this topic.