Customize links menu in Drupal

Tested on: Zen theme, Drupal 5.7

  1. Copy function theme_links from includes/
  2. Paste it into your template.php
  3. Rename it in theme_primarylinks (or anything you want)
  4. In your page.tpl.php, change
    1. print theme(‘links’, $primary_links);
    2. to print theme(‘primarylinks’, $primary_links);
  5. Apply some changes to theme_primarylinks to customize your primary links.

According to theme manual, for any first argument passed to theme function a theme_functionname function is called.

6 responses to “Customize links menu in Drupal”

  1. Thanks, Great tip!
    I’m using this technique in a site I’m developing on Drupal5.

    I found a simple way to change image depending on the active link too, here is a piece of my code form “theme_primarylinks” function (I ave a PrimaryLink folder in my images in there I have a menuname.png image and a menunameActive.png image):

    // Initialize fragment and query variables.
    $link[‘query’] = isset($link[‘query’]) ? $link[‘query’] : NULL;
    $link[‘fragment’] = isset($link[‘fragment’]) ? $link[‘fragment’] : NULL;

    if (isset($link[‘href’])) {
    $linkactive = “”;
    // should this button be active?
    if(substr($link[‘attributes’][‘class’], -6) == “active” ) { $linkactive = “Active”;}
    // if an active image exixts use it!
    if(file_exists(“/opt/lampp/htdocs/” . path_to_subtheme() . “/images/PrimaryLinks/” . $link[‘title’] . $linkactive . “.png”)) {

    $output .= l(“”,
    $link[‘href’], $link[‘attributes’], $link[‘query’], $link[‘fragment’], FALSE, $html = TRUE);

    else {
    $output .= l($link[‘title’], $link[‘href’], $link[‘attributes’], $link[‘query’], $link[‘fragment’], FALSE, $html);


  2. How about a video on how to turn the primary links to an image. Gosh, I’ve been hours looking for a step by step tutorial. I feel so frustrated =( I’m not that versed in PHP, whew.. help? anyone.. at least just reference. =)

%d bloggers like this: