2

Doe's anybody know how to add metatags such as fb:admins or fb:app_id into drupal 7 ? I use meta tags module for D7 but for some reason theese tags are not included. Thank you for answers.

12

The drupal 7 Metatags module has built-in Facebook opengraph support as an add-on module. If your specific metatag is not covered, the Meta tags module allows you to add it manualy.

Although not recommended, if you need custom code for specific pages, you may use the theme's preprocess hook. For example, here is the one I wrote on the preprocess-page.inc file on the preprocess directory of my Omega sub-theme (for other themes, you may need to write the code in a hook_preprocess_page function on template.php):

<?
  // Add og:title and og:description for the front page
  if($vars['is_front'] == TRUE){
    $element = array(
      '#tag' => 'meta',
      '#attributes' => array(
        "property" => "og:title",
        "content" => t("Druvision - Drupal News"),
      ),
    );
    drupal_add_html_head($element,'og_title');

    $element = array(
      '#tag' => 'meta',
      '#attributes' => array(
        "property" => "og:description",
        "content" => t("Druvision is a team of web solution experts focused on enterprise systems, open source development, responsive design and Drupal project management."),
      ),
    );
    drupal_add_html_head($element,'og_description');
  }

  // Add og:image
  global $base_url;
  $img =  $base_url.base_path() . drupal_get_path('theme', 'MYTHEME') . "/logo.png";
  if($vars['is_front'] != TRUE){
    if(isset($vars['node']->field_image['und'][0]['uri'])){
      $img = file_create_url($vars['node']->field_image['und'][0]['uri']);
    }
  }
  $element = array(
    '#tag' => 'meta',
    '#attributes' => array(
      "property" => "og:image",
      "content" => $img,
    ),
  );
  drupal_add_html_head($element,'facebook_share_image');
?>

Note: The question is old, but I've found it in search so other people are looking for it, so I answer it for the completeness of this thread.

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.