0
votes

I am new to Drupal 7.

I have different basic pages, I want to loop through every page using the meta tag:

<meta http-equiv="refresh" content="20; url=http://sitename/node/page2" />

page 2 would have the meta tag

<meta http-equiv="refresh" content="10; url=http://sitename/node/page3" />

How can I do this? i want the meta tags to be added on basic pages only

I tried using the TEMPLATEUSED_preprocess_html to add the meta tag however I already realized it was wrong since it's not dynamic and applies to every page.

2

2 Answers

1
votes

drupal_add_html_head is useful to add tags to head, Please check the example below.

// First, we must set up an array
$element = array(
  '#tag' => 'link', // The #tag is the html tag - <link />
  '#attributes' => array( // Set up an array of attributes inside the tag
     'href' => 'http://fonts.googleapis.com/css?family=Cardo&subset=latin', 
     'rel' => 'stylesheet',
     'type' => 'text/css',
  ),
);
drupal_add_html_head($element, 'google_font_cardo');

This will output the following HTML:

<link href="http://fonts.googleapis.com/css?family=Cardo&amp;subset=latin" rel="stylesheet" type="text/css" />
1
votes

This is an old question, but it remains without a more specific response. It seems that we have to use preprocess_html to add a head element within template.php. $node isn't available (at least I couldn't access it from within template.php/preprocess_html) but I could get the path using drupal_get_path_alias, which is what the original question requested.

This is my working example:

function THEMENAME_preprocess_html(&$variables) {
  if (drupal_get_path_alias() == "node/45") {
    $meta_refresh = array(
      '#type' => 'html_tag',
      '#tag' => 'meta', 
      '#attributes' => array( 
         'http-equiv' => 'refresh',
         'content' => '900, url=/node/45',
      ),
    );
    drupal_add_html_head($meta_refresh, 'meta_refresh');
  }
}

Using a case statement might better serve Warren's two paths.