Log1x / navi

A developer-friendly alternative to the WordPress NavWalker.
https://github.com/Log1x/navi
MIT License
315 stars 30 forks source link

Add target attribute #49

Closed fabianwurk closed 2 years ago

fabianwurk commented 2 years ago

Is there a way for Navi to include 'target' attribute to menu links? I need just one item to go to target _BLANK.

fabianwurk commented 2 years ago

And just to add, I have enabled the target within the array:

  297 => {#14281 ▼
    +"active": false
    +"activeAncestor": false
    +"activeParent": false
    +"classes": false
    +"dbId": 297
    +"description": false
    +"id": 297
    +"label": "Test"
    +"objectId": "297"
    +"parent": false
    +"slug": "test"
    +"target": "_blank"
fabianwurk commented 2 years ago

I've also tried using a filter but it doesn't seem to have any effect on it:

add_filter( 'nav_menu_link_attributes', function ( $atts, $item, $args ) {
    if ( 297 === $item->ID ) {
        $atts['target'] = '_BLANK';
    }
    return $atts;
}, 10, 3 );
Log1x commented 2 years ago

wouldn't you just do:

<a href="..." target="{{ $item->target }}">...</a>