0

I'm working on a website with Drupal 8 and the metatags module. I need to not output the metatag og:image:url if the og:image exists.

If it possible to do using the module? If not I would have to create a module for that?

0

I found a module that did something similar and just changed a bit:

function remove_generator_page_attachments_alter(array &$attachments) {

  $has_image = false;
  $index_to_remove = -1;

  foreach ($attachments['#attached']['html_head'] as $key => $attachment) {

    if ($attachment[1] == 'og_image_url_0' || $attachment[1] == 'og_image_url') {
      $index_to_remove = $key;
    }

    if ($attachment[1] == 'og_image_0' || $attachment[1] == 'og_image') {
      $has_image = true;
    }
  }

  if($has_image && $index_to_remove > -1) {
    unset($attachments['#attached']['html_head'][$index_to_remove]);
  }

}
  • Which module are you referring to? – leymannx Nov 11 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.