1

I'm trying to add the onclick attribute to some menu links in Drupal 8 in order to track conversions with Google.

Here's a tutorial for adding onclick events in Drupal 7 that uses the Menu Attributes module.

For Drupal 8, I looked at the Link attributes module and the Menu Link attributes module but these only allow you to add classes, not set the value for onclick.

2
  • 2
    Can't you add the onclick event in a js file?
    – 4uk4
    Commented Aug 31, 2018 at 11:45
  • Attaching an event solely with JS is much cleaner, and won't require any extra modules
    – Clive
    Commented Aug 31, 2018 at 12:03

1 Answer 1

1

Seems Menu Item Extras is the way to go now. It makes menu items fieldable. And you probably also get the proper template suggestions already.

Menu Item Extras provides extra fields for the Menu Items without using additional entities. This module is NOT an alternative of all Mega Menu modules - it is unique implementation of Drupal core’s Menu system. All fields are placed upon the Menu Item edit/add form and use core Menu link content entity for storing all data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.