4

How can I add a menu link as /test#anchor and link to #anchor section on the test page?

I need to add a menu item that links to specific section on the target page. Drupal 7 had menu tokens to achieve it. How can I do this in Drupal 8?

2 Answers 2

5
  1. Add/edit a menu link
  2. Enter /test#anchor in the "Link" field
  3. Save the link
  4. You're done, make tea :)

Point being - fragments are accepted as part of the link in Drupal 8.

One exception seems to be the home page; it doesn't work with the <front> token, nor /#anchor. The fragment isn't rendered in either case.

3
  • Correct. I did the same but it's not working. There is a menu item in the footer that has anchored link menu item which does not seem to work as expected. Commented Jun 1, 2017 at 19:24
  • I just added a link /node/1#test and that worked fine. Maybe your theme is stripping it, try switching to a core theme temporarily to see
    – Clive
    Commented Jun 1, 2017 at 19:25
  • Right on the money. Theme was stripping it off. Thanks. Commented Jun 1, 2017 at 19:33
0

For the homepage enter: <front>#your-anchor in the link field

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.