Last active
October 24, 2023 09:14
-
-
Save humayunahmed8/251bfa03c75d5a294d48c1cc92262e9f to your computer and use it in GitHub Desktop.
Add LI Class for WP Nav Menu
This file contains 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
<?php | |
// Add Formal/Mobile Menu Link Class | |
function lhcorp_formal_menu_add_link_class( $atts, $item, $args ) { | |
// Specify the menu location or menu ID you want to target | |
$target_menu_location = 'formal-menu'; // Replace with the actual location or menu ID | |
// Check if the current menu matches the target menu | |
if ($args->theme_location === $target_menu_location) { | |
$class = 'glue-header__link nav-link'; // or something based on $item | |
$atts['class'] = $class; | |
} | |
return $atts; | |
} | |
add_filter( 'nav_menu_link_attributes', 'lhcorp_formal_menu_add_link_class', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Container, List Item, Menu Item Class