Add CSS Class to Last Menu Item Anchor Tag

/*
 * Add CSS Class to Last Menu Item Anchor Tag
 */
function add_specific_menu_atts( $atts, $item, $args ) {
    if ( $args->menu->count == $item->menu_order && $args->theme_location == 'primary' ) {
        $atts[ 'class' ] = 'btn-def';
    }

    return $atts;
}
add_filter( 'nav_menu_link_attributes', 'add_specific_menu_atts', 10, 3 );

Leave a Reply