Skip to content

Instantly share code, notes, and snippets.

@benoitmercusot
Created February 29, 2016 16:51
Show Gist options
  • Save benoitmercusot/4ff1c65edf3513fccadd to your computer and use it in GitHub Desktop.
Save benoitmercusot/4ff1c65edf3513fccadd to your computer and use it in GitHub Desktop.
WordPress "pseudo class" to display colored menu dynamically
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