wp-bootstrap-navwalker icon indicating copy to clipboard operation
wp-bootstrap-navwalker copied to clipboard

Support for Description field

Open bhubbard opened this issue 7 years ago • 14 comments

bhubbard avatar Mar 14 '17 19:03 bhubbard

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.

jasperf avatar Jun 22 '17 13:06 jasperf

Seems https://github.com/jaycbrf4/wp-bootstrap-navwalker has this. Perhaps it could be integrated.

jasperf avatar Jul 03 '17 05:07 jasperf

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?

pattonwebz avatar Jul 03 '17 13:07 pattonwebz

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. screen shot 2017-07-03 at 4 32 03 pm

jasperf avatar Jul 03 '17 13:07 jasperf

Perfect :+1:

pattonwebz avatar Jul 03 '17 13:07 pattonwebz

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.

pattonwebz avatar Sep 17 '17 19:09 pattonwebz

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.

jaycbrf4 avatar Nov 02 '17 19:11 jaycbrf4

Now just trying to make compatible with the BS4 code to get n-level submenus to work.

jaycbrf4 avatar Nov 02 '17 19:11 jaycbrf4

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]

pattonwebz avatar Nov 02 '17 19:11 pattonwebz

@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-

jaycbrf4 avatar Nov 08 '17 20:11 jaycbrf4

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) :)

pattonwebz avatar Nov 08 '17 21:11 pattonwebz

@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!

jasperf avatar Nov 09 '17 06:11 jasperf

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.

pattonwebz avatar Feb 11 '18 00:02 pattonwebz

for use description field https://github.com/AmiiirCom/wp-bootstrap-navwalker/blob/master/README.md#description-field

AmiiirCom avatar Apr 26 '19 12:04 AmiiirCom