Created
October 21, 2016 19:12
-
-
Save sewmyheadon/de6805d14367264bfdaf910f54c14cee to your computer and use it in GitHub Desktop.
Add class to specific WordPress navigation menu link
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
/** | |
* Add class to specific WordPress navigation menu link | |
* Reference: https://codex.wordpress.org/Plugin_API/Filter_Reference/nav_menu_link_attributes | |
*/ | |
add_filter('nav_menu_link_attributes', 'ivycat_account_secondary_menu_link_attributes', 10, 4); | |
function ivycat_account_secondary_menu_link_attributes($atts, $item, $args, $depth){ | |
if ($args->menu->slug == 'utility' && $item->ID == 26){ | |
$class = "account_button"; | |
// Make sure not to overwrite any existing classes | |
$atts['class'] = (!empty($atts['class'])) ? $atts['class'].' '.$class : $class; | |
} | |
return $atts; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Notes:
In this example:
utility
is the slug for the custom menu26
is the ID of that specific menu itemaccount_button
is the class or classes that you want to add to the link.