Tagged: breadcrumbs, parent
-
AuthorPosts
-
September 1, 2022 at 1:13 am #1363415
Dear Support Team:
I have created a main menu, with submenus, on my website, where the parent menu items (except for Home) are custom links pointing to the first child submenu Page under that parent (I like this UX technique). For example, the About menu item is a custom link (rather than a Page) that points to the actual Page for first child submenu item, Our Office Highlights. So if someone clicked/tapped on About, it would take them to the Our Office Highlight page. So there are no actual Pages for these main menu items (parents). And the menu structure under Appearance > Menus does reflect this hierarchical menu structure.
However, the breadcrumbs do not, in that they do not display the parent menu item when a child submenu is chosen. So if the submenu “Meet Us” under the About menu is chosen and we are taken to that page, the breadcrumbs display “Home / Meet Us”, rather than “Home / About / Meet Us”. Can you help me please to include the parents in the breadcrumbs (and of course make them links to those first child submenu pages).
Thank you,
GaryP.S. My login to Support says that my “support license has expired on December 7th, 2021”, but this is not true. In my ThemeForest login, it shows I have “3 months 25 Nov 2022 of support remaining” for my “Regular License” of “Enfold – Responsive Multi-Purpose Theme”. How do I rectify this?
September 2, 2022 at 9:38 am #1363587Hey Gary,
Thank you for the inquiry.
You can set page hierarchies if you want to include the parent pages in the breadcrumbs. In this case, you have to set About as the parent of the Meet Us page. Please check the link below for more info about Page Attributes > Page Parent option.
// https://wordpress.com/support/pages/page-options/
Regarding the support license, please try to forward your support license or key to the Themeforest team and ask them about the expiry.
Best regards,
IsmaelSeptember 6, 2022 at 5:37 pm #1364089Thank you, Ismael, for your reply. I appreciate your help.
The problem with your suggested parent solution is that there are no actual pages for most of my parent menus, as they are custom links pointing to their first child. For example, the About parent points to its first child, Our Office Highlights. So I can’t set the Parent Page of any of the child pages (e.g. Our Office Highlights, Meet Us, etc.), since the About page does not exist (even typing into that text box, “About”, doesn’t work, since it wants you to choose from the dropdown of existing pages).
Thanks,
GarySeptember 7, 2022 at 7:22 am #1364151Hi,
If you can’t set the About page as a parent page, we can use css to manually adjust the color of the parent menu item when viewing any of its child pages.
Example:
#top.page-id-38 #header #avia-menu #menu-item-146 > a > .avia-menu-text { color: red; }
This will change the color of the About menu item to red on the Meet Us page. Noticed the selector .page-id-38 and the selector #menu-item-146. The number 38 is the ID of the Meet Us page while 146 is the ID of the About menu item.
Best regards,
IsmaelSeptember 7, 2022 at 5:51 pm #1364237Thanks, Ismael.
But that doesn’t solve the problem of “About” not being in the breadcrumbs. In fact, I already change the color of the About parent menu item when any of it’s children are active.
What we’re really looking for is overriding some PHP or even JavaScript functions in some fancy way to insert the parent menu items that are custom links instead of pages into the breadcrumbs. I’m a computer programmer/analyst myself and could in theory do it. But frankly it would just be too much work for me to figure it all out. I was just hoping you guys have already run across this issue and have a solution in your pocket.
If none of you do, it might just be best for me to just hard-code the breadcrumbs in HTML on each page.
Thanks,
GarySeptember 8, 2022 at 8:42 am #1364287Hi,
Sorry about that. I forgot about the breadcrumbs. Again, if you can’t set the About page as parent page, you could try and use the avia_breadcrumbs_trail filter to manually adjust the breadcrumb trail on specific pages.
Example:
function avia_adjust_breadcrumb($trail) { if(is_page([23, 42, 8]) { $trail[1] = '<a href="https://site.com/new-home" title="About" rel="home" class="trail-begin">About Us</a>'; } return $trail; } add_filter('avia_breadcrumbs_trail', 'avia_adjust_breadcrumb', 50, 1);
The filter above should add the About Us trail when the active page has the ID 23, 42, or 8.
Best regards,
IsmaelSeptember 22, 2022 at 5:43 pm #1366015Thank you very much Ishmael. Your code does not quite work, as it returns the breadcrumb trail as “Home > Meet Us > About” instead of “Home > About > Meet Us”, but it gave me a starting point to produce the right code. FYI: you’re also just missing a closing “)” on the ‘if’ statement. Here is my solution, which works (I’m a programmer):
function avia_adjust_breadcrumb($trail) { /* We're assuming $trail is an array with sequential keys starting from [0], each element containing the breadcrumb for a menu item from an hierarchical menu structure, with the last element having the key 'trail_end' and containing the menu item breadcrumb of the current page. This function's purpose is to manage the situation where a parent menu item is a custom link instead of a page. Because Enfold's breadcrumbs don't include menu items that are custom links instead of pages, this function checks if the current page is a child of such a parent, and if it is, inserts that custom link type of parent breadcrumb into the $trail before the current page breadcrumb. Both the check if current page is a child of such a parent as well as the link of the parent are hardcoded in this function. For example, if the actual current breadcrumbs should be "Home > About > Meet Us", but About is a link instead of a page, then $trail comes into this function as { [0] => <the link to the Home page>, ['trail_end'] => "Meet Us" }, or in other words, "Home > Meet Us". So this function changes $trail to be "Home > About > Meet Us"--i.e. returns it as: { [0] => <the link to the Home page>, [1] => <the link to the page About points to (which could e.g. be its first child menu item, Our Office Highlights)>, ['trail_end'] => "Meet Us" }. */ $parentIsCustomLink = false; $parentBreadcrumb = ""; if (is_page([36, 38, 40, 42, 44])) { $parentIsCustomLink = true; $parentBreadcrumb = '<a href="https://www.mydomain.com/our-office-highlights/" title="About" rel="home" class="trail-begin">About</a>'; } /* >>> ADDITIONAL PAGE CHECKS INSERTED HERE <<< */ if ($parentIsCustomLink) { $elementCount = count($trail); $error = false; // If something is not as expected in $trail, then $error will be set to true. $customParentKey = 0; //Just initialize it to a numerical value in case there is no 'trail_end' key in $trail. $trailEndKeyExists = false; for ($i = 1; $i <= $elementCount; $i++) { $currentKey = key($trail); if ((string)$currentKey == 'trail_end') { $trailEndKeyExists = true; $customParentKey = $i-1; if ($i !== $elementCount) { $error = true; break; } } else $newTrail[$currentKey] = $trail[$currentKey]; next($trail); } if ($error) //Then just return $trail unchanged and exit return $trail; $newTrail[$customParentKey] = $parentBreadcrumb; $newTrail['trail_end'] = $trail['trail_end']; unset($trail); return $newTrail; } else return $trail; } add_filter('avia_breadcrumbs_trail', 'avia_adjust_breadcrumb', 50, 1);
Thanks again,
GarySeptember 26, 2022 at 10:27 am #1366314 -
AuthorPosts
- The topic ‘Breadcrumbs when a parent menu item is a custom link’ is closed to new replies.