4

Is there a code to add rel="nofollow" in the "Add new comment" link under teaser?

This is the code in the teaser as generated by D7:

Add new comment

So how I do I add rel="nofollow" in that line?

2

You can do this in preprocess as well. Better to use structured data as its meant to be an not push attributes as strings, that will bound to create an error at some stage because theme_link() wants attribute arrays, not strings.

function themename_preprocess_node(&$vars) {
   if ($vars['node']->type == 'blog') {
    $vars['content']['links']['comment']['#links']['comment-add']['attributes']['rel'][] = 'nofollow';
  }
}
2

You could do this by implementing hook_node_view_alter in your custom module or theme.

//replace MODULENAME below with your custom module's name
function MODULENAME_node_view_alter(&$build) {
  if ($build['#node']->type == 'book') {
    $build['links']['comment']['#links']['comment-add'] = "rel=\"nofollow\"";
  }
}

This is for node type book, you could replace it by the content type you are using.

Here is the Module developer's guide, which should get you started.

protected by Clive Oct 20 '12 at 10:39

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.