Last active
April 7, 2022 11:20
-
-
Save brendonexus/deca81ceb0378b1d8489fbaf4c0dad4b to your computer and use it in GitHub Desktop.
Add css class to menu item. WordPress/ACF
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
function custom_css_class_on_menu_item( $items, $args ) { | |
// loop | |
foreach( $items as &$item ) { | |
// vars | |
$class = get_field('css_class', $item); | |
// append class | |
if( $class ) { | |
$item->classes[] = $class; | |
} | |
} | |
// return | |
return $items; | |
} | |
add_filter('wp_nav_menu_objects', 'custom_css_class_on_menu_item', 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment