2

I would like to add the meta tag

`<meta name="robots" content="follow,noindex">`

to all nodes (content type is article) written by specific authors, not only for their new articles but for the few hundred that already exist.

I've installed metatag and metatags-quick, neither seem to offer the functionality I'm after. This is a drupal 7 installation.

I'd rather not have to edit the php, as I'm unfamiliar with that, but I will if I have to.

Does anyone know a way to do this?

1

I don't know of a metatag module which gives you that level of granularity; you might have to do it in code.

Fortunately, it's pretty easy. You'll need a custom module, in which you should implement hook_node_view(), and use drupal_add_html_head() to add the meta tag based on custom logic.

Very brief example:

function MYMODULE_node_view($node, $view_mode, $langcode) {
  if ($node->type == 'foo' && $view_mode == 'full') {
    if ($node->name == 'admin') {
      $tag = array(
        '#type' => 'html_tag',
        '#tag' => 'meta',
        '#attributes' => array(
          'name' => 'robots',
          'content' => 'follow,noindex',
        ),
      );
      drupal_add_html_head($tag, 'MYMODULE:robots:noindex');
    }
  }
}
  • I'm following the drupal tutorial on creating modules. Guess I'll have to learn PHP. I'll set this as the accepted answer once I've got it working. – Chor Hatara Hud'u Keturi Feb 12 '14 at 11:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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