Drupal 6, programtically add custom meta tags to pages

Assuming that we need to add custom meta tags by page url or node type, drupal hook_preprocess_page() is the last function called before displaying the page, so it’s the right place for doing that :

 * Implementation of hook preprocess_page
 * @param array $variables
function my_module_preprocess_page(&$variables) {
    //using path
    if(arg(1) == 'gallery'){
      //load existing node
      $node = node_load(arg(2));
     // the meta content.
      $head = ' .. ';
      $variables['head'] = drupal_get_html_head();

In this case path is : gallery/[nid]

2 Replies to “Drupal 6, programtically add custom meta tags to pages”

  1. Hi, You don’t need to load node, node is presented in variables:

    if (isset($variables[‘node’]) && $variables[‘node’]->type == ‘gallery’){
    // code here

Leave a Reply