我试图从drupal 7的头部取消规范标签。 我使用:
输出了template.php中的head元素function mytemplatename_html_head_alter(&$head_elements) {
print_r($head_elements);
}
给了我以下标准标签:
[drupal_add_html_head_link:canonical:</node/1>;] => Array
(
[#tag] => link
[#attributes] => Array
(
[rel] => canonical
[href] => /node/1
)
[#attached] => Array
(
[drupal_add_http_header] => Array
(
[0] => Array
(
[0] => Link
[1] => </node/1>; rel="canonical"
[2] => 1
)
)
)
[#type] => html_tag
)
我假设我可以使用html_head_alter挂钩取消设置,但以下操作无效:
function grocore_html_head_alter(&$head_elements) {
unset($head_elements['drupal_add_html_head_link:canonical']);
}
有什么想法吗?
由于
答案 0 :(得分:4)
unset($head_elements['drupal_add_html_head_link:canonical:</node/1>;']);
或每条路径
foreach (preg_grep('/^drupal_add_html_head_link:canonical:</', array_keys($head_elements)) as $key) {
unset($head_elements[$key]);
}