Created
February 29, 2016 16:51
-
-
Save benoitmercusot/4ff1c65edf3513fccadd to your computer and use it in GitHub Desktop.
WordPress "pseudo class" to display colored menu dynamically
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
add_action('wp_head', function() { | |
$items = wp_get_nav_menu_items('Your Menu Name Here'); | |
foreach ($items as $item) { | |
foreach ($item->classes as $class) { | |
if( preg_match('/([a-fA-F0-9]{3}){1,2}\b/', $class ) ) | |
echo '<style type="text/css">#menu-item-'.$item->ID.' a{color:#'.$class.'!important;}</style>'."\r\n"; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment