Drupal 7 : How to add meta tags programmatically to custom pages in Drupal

 Using hook_html_head_alter() or using hook_preprocess_html() we could add Meta tags and title.

Sample code for adding meta tag description are below , put code in MYTHEME/template.php. file


function MYTHEME_html_head_alter(&$head_elements) {
  $head_elements['metatag_description'] = array(
      '#theme' => 'metatag',
      '#tag' => 'meta',
      '#id' => 'metatag_description',
      '#name' => 'description',
      '#value' => 'Description for meta-tags',
      '#type' => 'html_tag',
    );
}

Or you can use the following code

function MYTHEME_preprocess_html(&$vars) {
  $metatag_description = array(
      '#type' => 'html_tag',
      '#tag' => 'meta',
      '#attributes' => array(
        'name' => 'description',
        'content' => 'Description for meta_tags',
      )
    );
    drupal_add_html_head($metatag_description, 'description');
}

1 comment:

Sapphire Solutions said...

Very interesting post..

About - Drupal 7 : How to add meta tags programmatically to custom pages in Drupal

Drupal Development Company

Drupal Module Development Services

Write a program in PHP to reverse a number

A number can be written in reverse order. For example 12345 = 54321 <?php   $ num = 23456;   $ revnum = 0;   while ($ num > 1)   {   $...