0

This is such a great script called fullPage.js

I managed to load the js file and css file and even with the Void Menu Module, managed to call anchor links, but I'm struggling with the data attributes part of the implementation of this cool code! Any help is greatly appreciated! How do I get data-attributes to work in Drupal 7.25? I mean, I need to add them to the menu, so that the html looks something like this:

<ul id="menu">
    <li data-menuanchor="firstPage"><a href="#firstPage">First slide</a></li>
    <li data-menuanchor="secondPage"><a href="#secondPage">Second slide</a></li>
    <li data-menuanchor="3rdPage"><a href="#3rdPage">Third slide</a></li>
    <li data-menuanchor="4thpage"><a href="#4thpage">Fourth slide</a></li>
</ul>

Just want to add it to the Main Menu in Drupal. Any idea how? Am trying to implement this on my homepage and using the Adaptive Sub-Theme with Display Suite Module installed, if that helps any.

Have added the following to template.php, but it makes no difference at all:

function MY_THEME_NAME_menu_link(&$variables) {
  $variables['element']['#attributes']['data-menuanchor'] = substr($variables['element']['href'], 1);
  return theme_menu_link($variables);
}

What am I doing wrong here?

3
  • it looks right. I am sure you've cleared caches to make sure it's picked up, but another thing to check is that MY_THEME_NAME matches the name in your subtheme's .info file exactly.
    – Jimajamma
    Jan 14, 2014 at 17:16
  • Ofcourse, this was the case. I have cleared my cache thousands of times. And MY_THEME_NAME was replaced with the actual themes name. This did not help! It does not work! Jan 14, 2014 at 18:17
  • 1
    I got the same issue using superfish. The answer was stackoverflow.com/a/22349886/785966
    – dotoree
    Oct 22, 2014 at 15:49

1 Answer 1

0

Now there is contributed module that will let you add custom attributes per menu item, you can find it here: Menu Links Attributes

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.