Hi,

I'd like to know how to add the meta tags description and keywords to the frontpage. Only meta tags content type and generator appear on my site.

and also how to modify those meta tags

Thank you for your help

Comments

gtsopour’s picture

Assigned: abonados » gtsopour
gtsopour’s picture

Title: adding metatags to the frontpage » Adding metatags to the frontpage (Drupal 7)
Category: task » support
Status: Active » Fixed
Issue tags: +Bluemasters theme, +bluemasters

Hello abonados

You can use drupal_add_html_head() for adding meta description and meta keywords in header. In Bluemasters theme template.php file, you can call hook_page_alter() for embeding meta. If you want to add meta description and meta keywords in your site then go to your template.php file and paste the code (display below):

function bluemasters_page_alter($page) {
   $meta_description = array(
            '#type' => 'html_tag',
            '#tag' => 'meta',
            '#attributes' => array(
                'name' => 'description',
                'content' =>  'some description here'
            )
   );
   $meta_keywords = array(
            '#type' => 'html_tag',
            '#tag' => 'meta',
            '#attributes' => array(
                'name' => 'keywords',
                'content' =>  'some, keywords'
            )
   );
drupal_add_html_head( $meta_description, 'meta_description' );
drupal_add_html_head( $meta_keywords, 'meta_keywords' );
}

Finally change 'content' with your content.

Thanks
George

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

ressa’s picture

Thanks @gtsopour, I tried to get your example to work with the Bartik theme, to only show the description on the front page, but couldn't make it work. It works if I use hook_preprocess_html in stead though:

function bartik_preprocess_html(&$variables) {

  if(drupal_is_front_page()) 
    { 
  //    print "is front page"; 
      $meta_description = array(
              '#type' => 'html_tag',
              '#tag' => 'meta',
              '#attributes' => array(
                  'name' => 'description',
                  'content' =>  'some description here'
              )
      );
      $meta_keywords = array(
              '#type' => 'html_tag',
              '#tag' => 'meta',
              '#attributes' => array(
                  'name' => 'keywords',
                  'content' =>  'some, keywords'
              )
      );
      drupal_add_html_head( $meta_description, 'meta_description' );
      drupal_add_html_head( $meta_keywords, 'meta_keywords' );
    } 
  else 
     { 
  //     print "is not front page"; 
  }
}

You can insert the site slogan like this (in stead of 'some description here'):
'content' => check_plain(variable_get('site_slogan', ''))

vlad074’s picture

Issue summary: View changes

Concerning to the first answer:
'some description here' - it is a static parameter,
how can i input a variable from "Metatag" module, non-static?
Or from something else module