You are here

function hook_metatags_attachments_alter in Metatag 8

Alter the meta tags for any page prior to page attachment.

Parameters

array $metatag_attachments: An array of metatag objects to be attached to the current page.

1 function implements hook_metatags_attachments_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

metatag_test_integration_metatags_attachments_alter in tests/modules/metatag_test_integration/metatag_test_integration.module
Implements hook_metatags_attachments_alter().
1 invocation of hook_metatags_attachments_alter()
metatag_page_attachments in ./metatag.module
Implements hook_page_attachments().

File

./metatag.api.php, line 51
Document all supported APIs.

Code

function hook_metatags_attachments_alter(array &$metatag_attachments) {
  if (\Drupal::service('path.matcher')
    ->isFrontPage() && \Drupal::currentUser()
    ->isAnonymous()) {
    foreach ($metatag_attachments['#attached']['html_head'] as $id => $attachment) {
      if ($attachment[1] == 'title') {
        $metatag_attachments['#attached']['html_head'][$id][0]['#attributes']['content'] = 'Front Page Title for Anonymous Users';
      }
    }
  }
}