Inject Your Own SEO Page Title and Meta Tags on Non-Node Pages

You can use this little snippet in a helper module if you need to inject your own meta tags description or keywords into a page without using something like the nodewords module. The Nodewords module is really nice but sometimes you just can't get it to work right on a Panels or Views page.

function MY_MODULE_preprocess(&$variables) {
  if (arg(0) == 'node' && in_array($variables['type'], array('YOUR-CONTENT-TYPE'))) {
    drupal_set_title($variables['title']. ' is a great city ');
    drupal_set_html_head('<meta name="keywords" content="drupal snippets, seo stuff, drupal rocks!" />');
    drupal_set_html_head('<meta name="description" content="Use the Drupal API for good." />');
  }
}

Contact Me

Feel free to contact me.

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.