Add Classes and Data to WordPress Menu Items

add_filter( 'nav_menu_link_attributes', 'wpse121123_contact_menu_atts', 10, 3 );
function wpse121123_contact_menu_atts( $atts, $item, $args )
{
  // The ID of the target menu item    data-what="body" data-what-class="form_box_on"
  $menu_target = 441;

  // inspect $item
  if ($item->ID == $menu_target) {
    $atts['data-what'] = 'body';
    $atts['data-what-class'] = 'form_box_on';
    $atts['data-source'] = 'main menu';
    $atts['class'] = 'video_form';
  }
  return $atts;
}
Comments