2011-09-15 41 views
0

如何刪除或更改Drupal 7中的現有元標記?在drupal 6中有drupal_set_header或類似的東西,但Drupal 7不知道這一點。Drupal - 如何更改/刪除元標記

有沒有什麼辦法可以做到這一點,而無需額外的模塊?目前我有2個元描述標籤,我不想要。

回答

0
function your-themme_html_head_alter(&$head_elements) { 

$remove = array(
     'apple-touch-icon57', 
     'apple-touch-icon72', 
     'apple-touch-icon114' 
); 

foreach ($remove as $key) { 
    if (isset($head_elements[$key])) { 
     unset($head_elements[$key]); 
    } 
} 

//add 
$appleIcon57px = array('#tag' => 'link', '#type' => 'html_tag', '#attributes' => array('rel' => 'apple-touch-icon', 'href' => '/misc/AMU-NUMERIQUE-ICONE-57.png', 'type' => 'image/png', 'media' => 'screen and (resolution: 163dpi)'),); 
$appleIcon72px = array('#tag' => 'link','#type' => 'html_tag', '#attributes' => array('rel' => 'apple-touch-icon', 'href' => '/misc/AMU-NUMERIQUE-ICONE-72.png', 'type' => 'image/png', 'media' => 'screen and (resolution: 132dpi)'),); 
$appleIcon114px = array('#tag' => 'link','#type' => 'html_tag', '#attributes' => array('rel' => 'apple-touch-icon', 'href' => '/misc/AMU-NUMERIQUE-ICONE-114.png', 'type' => 'image/png', 'media' => 'screen and (resolution: 326dpi)'),); 


$head_elements['apple-touch-icon57']=$appleIcon57px; 
$head_elements['apple-touch-icon72']=$appleIcon72px; 
$head_elements['apple-touch-icon114']=$appleIcon114px; 
} 
0
You can implement hook_menu() to add head tags in Drupal 7. 

/** 
* Implements hook_menu(). 
* @return array 
*/ 
function module-name_menu() { 
    $items['add-metatags'] = array(
    'page callback' => 'custom_metatags', 
    'access callback' => TRUE, 
    'type' => MENU_CALLBACK, 
); 

    return $items; 
} 

function custom_metatags() { 

    $html_head = array(
    'description' => array(
     '#tag' => 'meta', 
     '#attributes' => array(
     'name' => 'description', 
     'content' => 'Enter your meta description here.', 
    ), 
    ), 
    'keywords' => array(
     '#tag' => 'meta', 
     '#attributes' => array(
     'name' => 'keywords', 
     'content' => 'Enter your meta keywords here.', 
    ), 
    ), 
); 
    foreach ($html_head as $key => $data) { 
    drupal_add_html_head($data, $key); 
    } 

} 
+0

請提供解釋給答案 – Hatik