Current Status:
Thanks to your help, I have managed to add the is-active class to my links, however, on the homepage (/) EVERY link has now the is-active added and on the other pages there are still no is-active classes..
So, I have a CMS (Wordpress), that generates a-tags in my primary nav.
Using the functions.php file, I have already managed to add a custom class to these links.
However, I NEED these classes to be added BEFORE the href-attribute for a reason I do not understand.. :) (I am using a javascript to add an "is-active" class for the link one is currently on. And this works perfectly, if the class is before the href)
Here is my function in the functions.php file of my Wordpress theme:
function add_specific_menu_location_atts( $atts, $item, $args ) {
// check if the item is in the primary menu
if( $args->theme_location == 'primary' ) {
// add the desired attributes:
$atts['class'] = 'mdl-navigation__link';
}
return $atts;
}
add_filter( 'nav_menu_link_attributes', 'add_specific_menu_location_atts', 10, 3 );
This is what I use to create the is-active class.
<script type="text/javascript">
$(function() {
$('nav a[href$="/' + location.pathname.split("/")[1] + '"]').addClass('is-active');
});
</script>