首页 > 解决方案 > 需要帮助从 Drupal 8 中删除规范的 rel 链接

问题描述

我需要删除链接 rel="canonical"。我从元标记模块中删除了它,我还使用了一个应该删除它但它仍然存在的模块。

我删除了 Meta Tag 模块中的所有实例,并且我还使用了应该删除它的 Disable Link Rel 模块。它还在那里。

我需要从我的网站顶部删除此链接。

标签: drupal-8

解决方案


您也可以从 $variables['page']['#attached'] 数组中的 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
                )

推荐阅读