0

I have created a custom page using a tpl.php file and I want to add meta tag page title, abstract and description that page. Can anyone show me how to add these meta tags programatically to custom page?

$description = array(        
                 '#type' => 'html_tag',
                 '#tag' => 'meta',
                 '#attributes' => array(
                 'name' => 'description',
                 'content' => 'here all description goes',
               )
 );
drupal_add_html_head($description, 'description');

This is the code I am using to add description to my head. Thanks in advance.

1 Answer 1

5

In your theme's template.php file, you could add something like

/**
 * Implements hook_preprocess_html
 */
function THEME_NAME_preprocess_html(&$vars) {

  if (current_path() == 'my/custom/path') {
    $description = array(        
      '#type' => 'html_tag',
      '#tag' => 'meta',
      '#attributes' => array(
        'name' => 'description',
        'content' => 'here all description goes',
      )
    );
    drupal_add_html_head($description, 'description');
  }

}

Clear cache to register new preprocess function.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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