我需要删除链接rel="canonical“。我从Meta标签模块中删除了它,我也使用了一个应该删除它的模块,但它仍然存在。
我删除了Meta标记模块中的所有实例,还使用了应该删除它的Disable Link Rel模块。它还在那里。
我需要从我的网站头部删除此链接。
发布于 2019-07-25 15:34:58
你也可以在要修改的$variables‘hook_preprocess_html’数组中这样做。你必须先通过打印变量来检查
print '<pre>';print_r($variables['page']['#attached']);die; 然后检查并清空数组,如下所示:
if($variables['page']['#attached']['html_head'][1][1] == 'canonical_url') { $variables['page']['#attached']['html_head'][1][0]['#attributes'] = array(); }在我的例子中,打印的数组是这样的:
Array
(
[html_head] => Array
(
[0] => Array
(
[0] => Array
(
[#tag] => meta
[#attributes] => Array
(
[name] => title
[content] => test english 1 | localhost
)
)
[1] => title
)
[1] => Array
(
[0] => Array
(
[#tag] => link
[#attributes] => Array
(
[rel] => canonical
[href] => http://localhost/leadervinu_development/drupal-8.7.3/en/node/51
)
)
[1] => canonical_url
)https://stackoverflow.com/questions/57190800
复制相似问题