Skip to main content
Post Undeleted by Ajay Reddy
added 100 characters in body
Source Link
Ajay Reddy
  • 3.9k
  • 2
  • 25
  • 38

You can use menu_link_attributes and edit linkbelow code to set attributes. ThereThis will beadd an optionattribute to add attributesall links in the page. But make sure to each menu you savedadd the condition check for your URL.

Hope this helps.

/**
 * Implements template_preprocess_menu().
 */
function THEME_preprocess_menu(&$variables) {
  foreach ($variables['items'] as $item) {
    $item['attributes']->setAttribute('data-target', 'YOUR TARGET NAME');
  }
}

You can use menu_link_attributes and edit link. There will be an option to add attributes to each menu you saved.

Hope this helps.

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');
  }
}
Post Deleted by Ajay Reddy
Source Link
Ajay Reddy
  • 3.9k
  • 2
  • 25
  • 38

You can use menu_link_attributes and edit link. There will be an option to add attributes to each menu you saved.

Hope this helps.