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';
  }
}
| improve this answer | |
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.

| improve this answer | |

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