wp-bootstrap / wp-bootstrap-navwalker

A custom WordPress nav walker class to fully implement the Twitter Bootstrap 4.0+ navigation style (v3-branch available for Bootstrap 3) in a custom theme using the WordPress built in menu manager.
https://wp-bootstrap.github.io/wp-bootstrap-navwalker/
GNU General Public License v3.0
3.37k stars 1.94k forks source link

How to add class inside our anchor tags #247

Closed Danial-Pervaiz closed 7 years ago

Danial-Pervaiz commented 7 years ago

hi, how can insert class inside my anchor tags while working with wp-bootstrap-navwalker

http://stackoverflow.com/questions/42105407/how-to-make-custom-navigation-with-wordpress-wp-bootstrap-nawalker

eglyte commented 7 years ago

you need to edit bootstrap_navwalker.php ( lines 80 -94 )

$atts = array();
$atts['title']  = ! empty( $item->title )   ? $item->title  : '';
$atts['target'] = ! empty( $item->target )  ? $item->target : '';
$atts['rel']    = ! empty( $item->xfn )     ? $item->xfn    : '';
$atts['class']  = 'nav-link'; // class for anchor tag

// If item has_children add atts to a.
if ( $args->has_children && $depth === 0 ) {
    $atts['href'] = ! empty( $item->url ) ? $item->url : ''; // I have added links for items that has children
    $atts['data-toggle']    = ''; // removed data-toggle to enable show 2-nd level on hover
    $atts['class'] = 'nav-link dropdown-toggle'; //class for dropdown anchor tag
    $atts['aria-haspopup'] = 'true';
} else {
    $atts['href'] = ! empty( $item->url ) ? $item->url : '';
}
bhubbard commented 7 years ago

We recently updated to 2.0.5, so you may want to update and the lines you need to modify may have changed. With that said, I will leave this open, as we may be able to make the walker more filterable to modify classes as needed.

pattonwebz commented 7 years ago

In a future version of the walker assigning classes is a lot easier. I believe this fix still works with the current master branch so long as you adjust the line numbers to where this code is now found.

Since this fix work, and will be possible in future version, I am going to close this ticket for now in the interest of focusing on the active issues but feel free to reopen this issue if you have more comments about it.