Created
December 15, 2020 10:58
-
-
Save nfsarmento/f0112ce9626eb9b4d8230208493ee5db to your computer and use it in GitHub Desktop.
WordPress Menu add class to <a>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * 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