The ubermenu_anchor_attributes
filter allows you to control the attributes on the anchor of any menu item.
Example
This example adds the attribute data-my-att
with the value my-value
to menu item 99, which would result in an anchor like this
<a href="http://mysite.com/about" data-my-att="my-value">About</a>
Example filter code:
add_filter( 'ubermenu_anchor_attributes' , 'um_modify_anchor_atts' , 10 , 5 );
function um_modify_anchor_atts( $atts , $menu_item_type , $menu_item_id , $object_type , $object_id ){
//Target menu item 99
if( $menu_item_id == 99 ){
//Set a special attribute for this item's anchor
$atts['data-my-att'] = 'my-value';
}
return $atts;
}
It is critical to always return the $atts
array
Filter Definition
ubermenu_anchor_attributes
Your registered callback will be called once for each item in the menu. Each key in the returned array will become an attribute in the anchor with its associated value.
$atts
This is an array of anchor attributes in key/value pairs. Careful not to override existing attributes!
$menu_item_type
The type of menu item in Appearance > Menus.
$menu_item_id
This is the numeric ID of the menu item. Use this to target items individually.
$object_type
The type of object that the menu item points to.
$object_id
The ID of the object that the menu item points to.