Skip to content

Instantly share code, notes, and snippets.

@nfsarmento
Created December 15, 2020 10:58
Show Gist options
  • Select an option

  • Save nfsarmento/f0112ce9626eb9b4d8230208493ee5db to your computer and use it in GitHub Desktop.

Select an option

Save nfsarmento/f0112ce9626eb9b4d8230208493ee5db to your computer and use it in GitHub Desktop.
WordPress Menu add class to <a>
/*
* Menu
* add class to <a> on WP menu
*/
function ns_menu_add_class( $atts, $item, $args ) {
if($args->theme_location == 'topics') {
$class = 'term--single with-image'; // or something based on $item
$atts['class'] = $class;
}
return $atts;
}
add_filter( 'nav_menu_link_attributes', 'ns_menu_add_class', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment