17

I am trying to modify the HTML output in a Drupal 7 theme that I am creating.

Basically, instead of the < li >s containing just plain < a >s with text, I want to include some additional HTML inside the < a >.

I know that it's possible to modify the HTML created by the menus in Drupal. I can see the following call in page.tpl.php:

<?php print theme('links__system_main_menu', array(
      'links' => $main_menu,
      'attributes' => array(
        'id' => 'main-menu',
        'class' => array('links', 'clearfix'),
      ),
      'heading' => array(
        'text' => t(''),
        'level' => 'h2',
        'class' => array('element-invisible'),
      ),
    )); ?>

which apparently calls the theme function, which creates the output. One way to modify the output would be to modify the theme_links function in theme.inc, right?

http://api.drupal.org/api/drupal/includes--theme.inc/function/theme_links

I also know that you can put a hook in template.php to override the function which creates the HTML. I can't figure out how to create the actual override function. Can somebody point me in the right direction, please?

Jean-Michel Garcia
  • 2,359
  • 2
  • 23
  • 44
Donnie Thomas
  • 3,888
  • 8
  • 47
  • 70

1 Answers1

18

What you would do is implement a hook to modify the output, not modify the "theme.inc" file directly.

For example, the accepted answer on this page: Drupal Override Custom Menu Template


And as a general rule, when you want to modify the output of something, either implement a hook (in a module or in the template.php of the active theme) or use a template with a predefined file name when such a case exists (when no template already exists, you can also modify the list of template suggestions using a module or the theme).

Community
  • 1
  • 1
wildpeaks
  • 7,273
  • 2
  • 30
  • 35
  • 3
    The accepted answer uses theme_menu_item which is Drupal 6. The equivalent in Drupal 7 is theme_menu_item http://api.drupal.org/api/drupal/includes--menu.inc/function/theme_menu_link/7 – Rimian Nov 21 '11 at 09:16
  • @Rimian Drupal 7 uses theme_menu_link instead of theme_menu_item. – shasi kanth Mar 12 '13 at 10:46