I'm trying to use the preprocess function to change the default outpot of links <a href> to include Schema.org's itemprop="url" inside the anchor object, as well as adding a <span itemprop="title"> to the title of the link. For example:

<a href="www.example.com" itemprop="url"><span itemprop="title">Example Title</span></a>

*Just to clarify: I want to do this for any link, not just menu or breadcrumb links.

I have managed to do something similar with images using the following code inside my template.php file, but had no luck with adapting it to links:

function THEME_preprocess_image(&$vars)
$vars["attributes"]["itemprop"] = "image";

Source can be found here.

I know that Microdata module might be able to handle that with a few modifications, however, I'd rather do everything manually instead.

I have spent hours searching for solutions but couldn't find any.. Any help would be greatly appreciated, thanks!

1 Answer 1


So after spending some more time on the matter, I finally found the solution and I am posting it here in case anyone is interested.

Simply put the following code in your template.php file, inside your theme folder:

function YOUR-THEME_link($variables) {
  return '<a itemprop="url" href="' . check_plain(url($variables['path'], $variables['options'])) . '"' . drupal_attributes($variables['options']['attributes']) . '><span itemprop="title">' . ($variables['options']['html'] ? $variables['text'] : check_plain($variables['text'])) . '</span></a>';

Hope that helps.. Remember to change 'YOUR-THEME' to your theme's name, and don't forget to clear the cache.

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.