Remove the metaphor generator



  • Thought I'd make a little project on the new Drupal 8, which means there's a little question. It wasn't our decision. We need to get rid of the metathe generator in the seventh dupala, do this kind of metatag, and eight or this module is still raw or I can't deal with it, but I never cleaned up the metatag. How can you take him out like that?



  • Drupal 8 This challenge will be used https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!theme.api.php/function/hook_page_attachments_alter/8 which serves to remove or modify libraries, meta-tags, tags link and HTTP headlines. Hook called right after the call. https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21theme.api.php/function/hook_page_attachments/8 And in front of the page.

    Let's see the example of the removal of the meta-team GeneratorMobileOptimized and HandheldFriendly♪ Implemented hook_page_attachments_alter in file THEMENAME.theme or module:

    function  THEMENAME_page_attachments_alter(array &$attachments) {
        $unneeded_meta = ['HandheldFriendly', 'MobileOptimized', 'system_meta_generator'];
        foreach ($attachments['#attached']['html_head'] as $id => $attachment) {
            if (in_array($attachment[1], $unneeded_meta)) {
                unset($attachments['#attached']['html_head'][$id]);
            }
        }
    }
    

    As an example of the change in the meta-tags, consider the modifications viewportDrupal 8 Initially. viewport so:

    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    

    It needs to be changed to this:

    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    

    We'll change him accordingly. hook_page_attachments_alter Total THEMENAME.theme:

    function THEMENAME_page_attachments_alter(array &$attachments) {
        $viewport = array(
            '#type' => 'html_tag',
            '#tag' => 'meta',
            '#attributes' => array(
                'name' => 'viewport',
                'content' => 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no',
            ),
        );
        $attachments['#attached']['html_head'][] = [$viewport, 'viewport'];
    }
    

    http://drup.by/snippets/drupal-8-udalenie-i-izmenenie-metategov ♪




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2