Im trying to learn how to manipulate the html output of the main menu on the page.

- I have made a fresh install of drupal 7.23
- made a copy of the stark theme, renamed it to t1 and placed it in the site/all/theme folder
- added the theme as my default them in drupal
- created a simple page called 'About page'
So now I have on my page:

Main menu
Home About page

Id really would like to add fx.|| around the links, so it looked like this |Home||About page| or alter the

  • and
    tag in others way I would see fit.

    As I understand the api I need to create a template.php file an ad a hook?

    - So I created an empty template.php file in the t1 theme folder an added the following code:

    function t1_menu_link(array $variables) {
    $element = $variables['element'];
    $sub_menu = '';

    if ($element['#below']) {
    $sub_menu = drupal_render($element['#below']);
    $output = l($element['#title'], $element['#href'], $element['#localized_options']);
    return '|

  • |' . $output . $sub_menu . "
  • \n";
    But the only place that change happens is in the adminstration submenu.

    I have tried a gazillon other options of the function and also tried creating it in a page.tlp.php file, but no matter what nothing tuches the mani menu 'items'/ links.

    I have almost given up now, really hope somebody can help me out.


    Quke’s picture

    I found the function that renders the menu:

    its in includes/theme.inc line 1685

    function theme_links

    So I have copied the entire funtion to my template.php

    Change a bit by adding | in front of the

  • tag, nothing happens.

    I then altereret the funtion name to t1_links, as suggested in many posts around the forum, that srewed up everything, my admin menu totally disappeared 'puff'.

    Found out to restor it though.

    I guess its that function I need to hook, but how and where?

    Any help would really really be appreciated.

  • Quke’s picture

    No one who can help? please?

    NielsSndt’s picture

    Hi Quke,

    Am I right that you want to change the look of your menu from

    Home bla bla blubb


    Home | bla | bla | blubb


    Doing it via CSS, seems to be the easiest option here?



    Quke’s picture

    Hi Niels

    Thx for the reply. What I wanted was to take control over the html output of the main menu.
    I figured it out =)

    What I did, if anybody else should be looking for the same solution:
    the html is manipulated in template.php and the menu itself is rendered/ drawn in paget.tpl.php. So you will need to have both these files in your theme.

    In template.php I did/ add the following:
    (fer_v2 is the name of my theme)

    function fer_v2_links__system_main_menu($variables) {
    $link = $variables['links'];
      $html = "
    \n"; $html .= "
      \n"; foreach ($variables['links'] as $link) { /************************ *echo url( $link['href'], array('absolute' => true, 'alias' => false )); *url() er den funtion som bruges til at hive den rene url sti ud. ************************/ $html .= "
    • "; $html .= ' false )).'">' . $link['title']. ''; $html .= '
      '; $html .= "
    • "; } $html .= "
    \n"; $html .= "
    \n"; return $html; }

    To render it in page.tpl.php you need to add this:
    print theme('links__system_main_menu', array('links' => $main_menu, 'attributes' => array('id' => 'main-menu')));

    So for my theme the complete construction of the main menu looks like this:
    if ($main_menu || $secondary_menu):

     //print theme('links__system_main_menu', array('links' => $main_menu, 'attributes' => array('id' => 'main-menu', 'class' => array('links', 'inline', 'clearfix'))));
            			print theme('links__system_main_menu', array('links' => $main_menu, 'attributes' => array('id' => 'main-menu')));


    Hope it will help others.
    PM me if you have questions =) cheers