wp-bootstrap-navwalker
wp-bootstrap-navwalker copied to clipboard
Support for Description field
Was just looking into adding a description field to a basic menu based on your walker. Would be great to have this so I can create menus with descriptions loaded from the menu description field.
Seems https://github.com/jaycbrf4/wp-bootstrap-navwalker has this. Perhaps it could be integrated.
Hey @jasperf, I have some time this coming week. I will look into a way to impliment some kind of support for descriptions within the walker. I do not think Bootstrap has any kind of styling or classname guidelines for descriptions do I'm not sure how best to impliment it. Do you have any screenshots of what you would expect descriptions to look like in the menu and inside a drop-down?
See https://imwz.io where I used the bootstrap walker as shared. Had to do some styling, but there you can see it at work. And here below a screenshot as well, but not using a dropdown. And I do think most people will not use it in a dropdown, but in a one level menu. If I do remember one where they do I will add it here as well.
Perfect :+1:
I've played around with this some and I struggle to add it to make it work correctly and stay stylistically neutral. For this kind of thing descriptions are going to be ver subjective and based on the theme it is used with. For that reason I won't be adding a feature to output descriptions by default.
I've also played around with the idea of offering a toggle and a filter for outputting them and I think that's a better avenue to go down. Toggle them on with by passing a true/false argument and then the theme author could style and use them however is best for that situation. I do not have working code to do this at the moment but it is something I am wanting to include.
My version with the added support for descriptions works just fine. I have even been able to create a MEGA-Menu by adding Bootstrap HTML as the description content.
Now just trying to make compatible with the BS4 code to get n-level submenus to work.
Hey @jaycbrf4 I would encourage you not to use description field for entering HTML content. Any time you output the description to the page you should be escaping the HTML or stripping tags from it so that your walker doesn't introduce XSS problems on sites it's in use at.
As for making things work with BS4 I have an updated version in the v4 branch of this repo with the very latest version of that code found here: https://github.com/wp-bootstrap/wp-bootstrap-navwalker/pull/307. It works with [email protected]
@jasperf I have removed the 'strip-tags' filter as per @pattonwebz instruction but left the ability to add a description with a class so it can be styled-
Yep, tested it and worked fine for me. Worth a try if you still need description fields (or indeed a fully fledged mega-menu style nav) :)
@jaycbrf4 I will test that out on the theme I mentioned earlier. Not in use on the link mentioned, but will check it locally. Thanks!
After a lot of thinking about this I came to the conclusion that it requires too much opinionated design input to add descriptions natively to the walker so I won't be adding that feature to it directly - but there is a filter that can be used to update what gets output at certain points in and around the nav item.
There is a filter (nav_menu_item_args
) applied to the $args
of each item with $args->before
, $args->after
, $args->link_before
and $args->link_after
methods. Each of those values is output in the logical place that it describes: before and after the nav item and directly before and after the link for the item.
Descriptions for items could be added at one of those locations through the filter and output markup that fits the theme it would be used in.
for use description field https://github.com/AmiiirCom/wp-bootstrap-navwalker/blob/master/README.md#description-field