You can use below code to set attributes. This will add an attribute to all links in the page. But make sure to add the condition check for your URL. /** * Implements template_preprocess_menu(). */ function THEME_preprocess_menu(&$variables) { foreach ($variables['items'] as $item) { $item['attributes']->setAttribute('data-target', 'YOUR TARGET NAME'); } }