How I can add itemprop="url" for each link (<a>) in main menu?

So, I need to get from

<a href="/node/114" data-drupal-link-system-path="node/114">Test</a>


<a href="/node/114" data-drupal-link-system-path="node/114" itemprop="url">Test</a>

Is it possible to do it in preprocess? I would like not to use any module for this.

1 Answer 1



function HOOK_link_alter(&$variables) or function HOOK_preprocess_menu(&$variables)

Or just override the menu template (menu--main.html.twig) and replace line

{{ link(item.title, item.url, {'class': link_classes}) }}


{{ link(item.title, item.url, item.attributes.addClass(link_classes).setAttribute('itemprop', 'url') }}

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.