Hi all,

I'm trying to modify the og:description metatag fro a specific node type, so here what I did:

function myModule_metatag_metatags_view_alter(&$output, $instance) {

  if ($instance == 'node:media_gallery') {
    if (isset($output['og:description']['#attached']['drupal_add_html_head'][0][0]['#value'])) {
      $output['og:description']['#attached']['drupal_add_html_head'][0][0]['#value'] = _myModule_get_description();
    }
  }

}

Now I have to write the callback function _myModule_get_description() where I'm going to build the description based on some fields belonging to the node.

The problem is that I don't know how to retrieve these node information (nid, fields and so on) from here.

Please help me, I'm not a programmer but I want learn how to do this kind of stuff.

Thank you very much for give me some advices

Comments

DamienMcKenna’s picture

FYI it might be easier to create a new set of defaults for that content type and then just build a token to insert the data you want?

MXT’s picture

I've found this working solution for now:

function _myModule_get_description()  {
  if ($node = menu_get_object()) {
    $tid = field_get_items('node', $node, 'field_ref_sez');
    $description = .... do stuff with $tid
    return $description;
  }
}

DamienMcKenna: thank you, I'll go to explore your suggestion with token (despite I absolutely don't know where to start..)