Add ID to target navigation link

I wasn’t able to find something that would add an id, but I did find something that would give me a class…this way I can target the class using jQuery. The default id’s and classes are ok, but the solution I found is much better because no matter which website you apply it to it will work, I don’t ever have to go back and change the link class or id. I was able to find a function that adds a class with the page name…so as long as I make sure the page names remain the same I’m golden 🙂

Add to functions.php:

function menu_css_class($css_class, $page){
    $css_class[] = "nav_" . $page->post_name;
    return $css_class;
}
add_filter("page_css_class", "menu_css_class", 10, 2);

Set it and forget it, I love it!

Thanks,
Josh