Skip to content

Instantly share code, notes, and snippets.

@xlawok
Created June 17, 2020 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xlawok/009ab14eeda6e4d1855d5c2bb103703b to your computer and use it in GitHub Desktop.
Save xlawok/009ab14eeda6e4d1855d5c2bb103703b to your computer and use it in GitHub Desktop.
Wordpress add custom styles to menu nav (with carbon fields)
// Adding a custom color and weight to the links
add_filter('nav_menu_link_attributes', 'crb_nav_menu_link_attributes', 10, 4);
function crb_nav_menu_link_attributes($atts, $item, $args, $depth) {
$crb_color = carbon_get_nav_menu_item_meta($item->ID, 'nav_color');
$crb_weight = carbon_get_nav_menu_item_meta($item->ID, 'nev_weight');
$crb_color = ! empty( $crb_color ) ? ' color: ' . $crb_color . '; ' : '';
$crb_weight = ! empty( $crb_weight ) ? ' font-weight: ' . $crb_weight . '; ' : '';
$atts['style'] = $crb_color.$crb_weight;
return $atts;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment