Add microdata to breadcrumbs - Some trouble with hooks I'm trying to add microdata to the breadcrumbs. I found on the web this fix which I tried to include to my own SEO module like this:

function mymod_page_alter(&amp;$variables) {
    if (!isset($variables['breadcrumb'])) {
        $variables['breadcrumb'] = theme('my_microdata', array('breadcrumb' =&gt; drupal_get_breadcrumb()));
    }
}
function mymod_theme($existing, $type, $theme, $path) {
  return array(
    'my_microdata' =&gt; array(
     'variables' =&gt; array('breadcrumb' =&gt;array()),
    ),
  );
}
function mymod_menu_breadcrumb_alter(&amp;$active_trail, $item){
  foreach($active_trail as $id=&gt;$active_trail_item){
    $active_trail[$id]['localized_options']['attributes']['itemprop'][]="url";
  }
}
function theme_my_microdata($variables){
 $breadcrumb=$variables['breadcrumb'];
print_r(debug_backtrace());
 $output="*+*+*+*+*";
  if (!empty($breadcrumb)) {
    // Provide a navigational heading to give context for breadcrumb links to
    // screen-reader users. Make the heading invisible with .element-invisible.
    $output = '&lt;h2 class="element-invisible"&gt;' . t('You are here') . '&lt;/h2&gt;';
    $output .= '&lt;div class="breadcrumb"&gt;';
    $separator="";
    foreach($breadcrumb as $breadcrumb_item){
      $output.='&lt;span typeof="datav:Breadcrumb"&gt;'.$separator.$breadcrumb_item."&lt;/span&gt;";
      $separator="»";
    }
    $output .='&lt;/div&gt;';
  }

    return $output."xXxXxXx";
}


So far I checked that all this code is executed. But this theming is not applied on my page. Why does my code not work? Could this been related with the module breadcrumb? I know that this output will be garbage but I cannot see the result.

If I guess right than is the output created by theme.inc line 1682ff theme_breadcrumb(...)instead of my code. How can I change that?



I just found the theme_breadcrumbs there is shown in their solution this line:

function YOURTHEME_breadcrumb($variables) {


Well can YOURTHEME my module name or have I to build a theme?
Your implementation of hook_page_alter() doesn't work because the parameter passed to the hook ($page) doesn't contain $page['breadcrumb'].

I used the following code to verify the content of the parameter passed as argument.

$path = 'node/14';

if ($router_item = menu_get_item($path)) {
  if ($router_item['access']) {
    if ($router_item['include_file']) {
      require_once DRUPAL_ROOT . '/' . $router_item['include_file'];
    }
    $page_callback_result = call_user_func_array($router_item['page_callback'], $router_item['page_arguments']);
  }
}

$main_content_display = &amp;drupal_static('system_main_content_added', FALSE);

if (is_string($page_callback_result) || (is_array($page_callback_result) &amp;&amp; (!isset($page_callback_result['#type']) || ($page_callback_result['#type'] != 'page')))) {
  drupal_set_page_content($page_callback_result);
  $page_callback_result = element_info('page');
}

foreach (module_implements('page_build') as $module) {
  $function = $module . '_page_build';
  $function($page_callback_result);
}

drupal_alter('page', $page_callback_result);

if (!$main_content_display) {
  $page_callback_result['content']['system_main'] = drupal_set_page_content();
}

dsm($page_callback_result);


"node/14" is the path for an "Article" node I have on my test site.
The code has been created looking at the code of different Drupal functions: drupal_deliver_html_page(), drupal_deliver_page(), and menu_execute_active_handler(). It requires the Devel module, as it uses one of its functions.

This is the output given by dsm().



You can override the theme function used for the breadcrumb, implementing hook_theme_registry_alter().

function mymodule_theme_registry_alter(&amp;$theme_registry) {
  if (isset($theme_registry['breadcrumb'])) {
    $theme_registry['breadcrumb']['function'] = 'theme_mymodule_breadcrumb';
  }
}


theme_mymodule_breadcrumb() is the function that replaces theme_breadcrumb(), and it gets the same parameters.


  $variables: An associative array containing:
  
  
  breadcrumb: An array containing the breadcrumb links.
  


The theme function should be overridden if you want to alter its output. If you want to alter the value of the variables passed to theme_breadcrumb(), with Drupal 7 you can implement a preprocess function.

function mymodule_preprocess_breadcrumb(&amp;$variables) {
  // Your code.
}