Hi

I've been trying to find a solution for 2 days, finally decided to ask for help. I am running drupal 5 with the aberdeen theme, which is great but for SEO purposes i'm trying to add rel="nofollow" to each link in the primary menu.

This may be really easy and i'm no php coder, html and css are my limit but I have been looking in the template.php and the common.inc files i'm sure the solution is tweaking something in one of these files.

I have tried the nofollow module which gave me the options but never worked, I did follow the instructions and added the code to the template.php file.

I also tried the nofollowlist module but it doesn't have the option to tweak the primary list. I see drupal 6 has the menu_attributes modules which would work if I wasn't using drupal 5 Pah!!!

Can anyone help or suggest a remedy, i'll put up the template code if it helps????

Cheers

Briz

Comments

vm’s picture

http://drupal.org/project/nofollow may be worth investigating

brizzo’s picture

Hi very misunderstood

I have used this module it installed ok and i had to add some extra code to the template file but it has never worked!! Any other ideas??

cheers

vm’s picture

none from me no. I've never had a need for no follow in primary links and as such haven't researched it beyond what I did for you.

fuldespanto’s picture

Try Menu Attributes, it provides you rel, among others

http://ftp.drupal.org/files/projects/menu_attributes-6.x-2.0-beta1.tar.gz

jasom’s picture

Add rel="nofollow" for Drupal 7 without any additional module usign template.php hack:

Complete code to understand the problem:

Add rel="nofollow" to specific paths:

function THEMENAME_menu_link(&$variables) {
    $system_paths = array(
        'node/22',
        'taxonomy/term/11',
    );

    if (in_array($variables['element']['#href'], $system_paths)) {
        $variables['element']['#localized_options']['attributes']['rel'][] = 'nofollow';
    }

    $element = $variables['element'];
    $sub_menu = '';

    if ($element['#below']) {
        $sub_menu = drupal_render($element['#below']);
    }
    $output = l($element['#title'], $element['#href'], $element['#localized_options']);
    return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}

Simpliefied code for final use:

function THEMENAME_preprocess_menu_link(&$variables) {
    $system_paths = array(
        'node/22',
        'taxonomy/term/11',
    );

    if (in_array($variables['element']['#href'], $system_paths)) {
        $variables['element']['#localized_options']['attributes']['rel'][] = 'nofollow';
    }
}

Will add rel="nofollow" to all items in menu-footer (menu_footer):

Dont forget to change menu_footer part to your desired menu:

function THEMENAME_preprocess_menu_link(&$variables) {
    if ($variables['element']['#theme'] == 'menu_link__menu_footer') {
        $variables['element']['#localized_options']['attributes']['rel'][] = 'nofollow';
    }
}

Will add rel="nofollow" to all menu items

function THEMENAME_preprocess_menu_link(&$variables) {
     $variables['element']['#localized_options']['attributes']['rel'][] = 'nofollow';
}