Skip to main content
added 9 characters in body
Source Link
Andrew Nim
  • 865
  • 4
  • 10

It seems you want to generate proper metatags for your node pages (blogs). To generate them dynamically i propose to add to your module.module file next code with hook_entity_view function:

  function your_module_entity_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {

  if ($entity->getEntityTypeId() == 'node') {
      $bundle = $entity->bundle();
      switch ($bundle){
          case 'blog':
              $image = $entity->get('field_image');
              $image_id = $image->getValue()[0]['target_id'];
              $image_file = \Drupal\file\Entity\File::load($image_id);
              $uri = $image_file->uri->value;
              $facebook_image_url = Drupal\image\Entity\ImageStyle::load('your_facebook_style')->buildUrl($uri);
              $facebook_metatag = [
                  '#tag' => 'meta',
                  '#attributes' => [
                    'property' => 'og:image',
                    'content' => $image_url$facebook_image_url,
                  ],
                ];
               $build['#attached']['html_head'][] = [$facebook_metatag, 'facebook_metatag'];
// the same for other social networks:

$twitter_image_url = Drupal\image\Entity\ImageStyle::load('your_twitter_style')->buildUrl($uri);
//etc
                  break;
              
          }
        
      }
    
    }

And you get this metatag type meta property="og:image" content="http://static01.nyt.com/images/2015/02/19/arts/international/19iht-btnumbers19A/19iht-btnumbers19A-facebookJumbo-v2.jpg" Also you can add any metatag in such a manner:

 $facebook_metatag = [
    '#tag' => 'meta',
    '#attributes' => [
             'property' => 'og:title',
             'content' => $your_node_title,
          ],
   ];
   $build['#attached']['html_head'][] = [$facebook_metatag, 'facebook_metatag'];

It seems you want to generate proper metatags for your node pages (blogs). To generate them dynamically i propose to add to your module.module file next code with hook_entity_view function:

  function your_module_entity_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {

  if ($entity->getEntityTypeId() == 'node') {
      $bundle = $entity->bundle();
      switch ($bundle){
          case 'blog':
              $image = $entity->get('field_image');
              $image_id = $image->getValue()[0]['target_id'];
              $image_file = \Drupal\file\Entity\File::load($image_id);
              $uri = $image_file->uri->value;
              $facebook_image_url = Drupal\image\Entity\ImageStyle::load('your_facebook_style')->buildUrl($uri);
              $facebook_metatag = [
                  '#tag' => 'meta',
                  '#attributes' => [
                    'property' => 'og:image',
                    'content' => $image_url,
                  ],
                ];
               $build['#attached']['html_head'][] = [$facebook_metatag, 'facebook_metatag'];
// the same for other social networks:

$twitter_image_url = Drupal\image\Entity\ImageStyle::load('your_twitter_style')->buildUrl($uri);
//etc
                  break;
              
          }
        
      }
    
    }

And you get this metatag type meta property="og:image" content="http://static01.nyt.com/images/2015/02/19/arts/international/19iht-btnumbers19A/19iht-btnumbers19A-facebookJumbo-v2.jpg" Also you can add any metatag in such a manner:

 $facebook_metatag = [
    '#tag' => 'meta',
    '#attributes' => [
             'property' => 'og:title',
             'content' => $your_node_title,
          ],
   ];
   $build['#attached']['html_head'][] = [$facebook_metatag, 'facebook_metatag'];

It seems you want to generate proper metatags for your node pages (blogs). To generate them dynamically i propose to add to your module.module file next code with hook_entity_view function:

  function your_module_entity_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {

  if ($entity->getEntityTypeId() == 'node') {
      $bundle = $entity->bundle();
      switch ($bundle){
          case 'blog':
              $image = $entity->get('field_image');
              $image_id = $image->getValue()[0]['target_id'];
              $image_file = \Drupal\file\Entity\File::load($image_id);
              $uri = $image_file->uri->value;
              $facebook_image_url = Drupal\image\Entity\ImageStyle::load('your_facebook_style')->buildUrl($uri);
              $facebook_metatag = [
                  '#tag' => 'meta',
                  '#attributes' => [
                    'property' => 'og:image',
                    'content' => $facebook_image_url,
                  ],
                ];
               $build['#attached']['html_head'][] = [$facebook_metatag, 'facebook_metatag'];
// the same for other social networks:

$twitter_image_url = Drupal\image\Entity\ImageStyle::load('your_twitter_style')->buildUrl($uri);
//etc
                  break;
              
          }
        
      }
    
    }

And you get this metatag type meta property="og:image" content="http://static01.nyt.com/images/2015/02/19/arts/international/19iht-btnumbers19A/19iht-btnumbers19A-facebookJumbo-v2.jpg" Also you can add any metatag in such a manner:

 $facebook_metatag = [
    '#tag' => 'meta',
    '#attributes' => [
             'property' => 'og:title',
             'content' => $your_node_title,
          ],
   ];
   $build['#attached']['html_head'][] = [$facebook_metatag, 'facebook_metatag'];
added 415 characters in body
Source Link
Andrew Nim
  • 865
  • 4
  • 10

It seems you want to generate proper metatags for your node pages (blogs). To generate them dynamically i propose to add to your module.module file next code with hook_entity_view function:

  function your_module_entity_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {

  if ($entity->getEntityTypeId() == 'node') {
      $bundle = $entity->bundle();
      switch ($bundle){
          case 'blog':
              $image = $entity->get('field_image');
              $image_id = $image->getValue()[0]['target_id'];
              $image_file = \Drupal\file\Entity\File::load($image_id);
              $uri = $image_file->uri->value;
              $facebook_image_url = Drupal\image\Entity\ImageStyle::load('your_facebook_style')->buildUrl($uri);
              $facebook_metatag = [
                  '#tag' => 'meta',
                  '#attributes' => [
                    'property' => 'og:image',
                    'content' => $image_url,
                  ],
                ];
               $build['#attached']['html_head'][] = [$facebook_metatag, 'facebook_metatag'];
// the same for other social networks:

$twitter_image_url = Drupal\image\Entity\ImageStyle::load('your_twitter_style')->buildUrl($uri);
//etc
                  break;
              
          }
        
      }
    
    }

And you get this metatag type meta property="og:image" content="http://static01.nyt.com/images/2015/02/19/arts/international/19iht-btnumbers19A/19iht-btnumbers19A-facebookJumbo-v2.jpg" Also you can add any metatag in such a manner:

 $facebook_metatag = [
    '#tag' => 'meta',
    '#attributes' => [
             'property' => 'og:title',
             'content' => $your_node_title,
          ],
   ];
   $build['#attached']['html_head'][] = [$facebook_metatag, 'facebook_metatag'];

It seems you want to generate proper metatags for your node pages (blogs). To generate them dynamically i propose to add to your module.module file next code with hook_entity_view function:

  function your_module_entity_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {

  if ($entity->getEntityTypeId() == 'node') {
      $bundle = $entity->bundle();
      switch ($bundle){
          case 'blog':
              $image = $entity->get('field_image');
              $image_id = $image->getValue()[0]['target_id'];
              $image_file = \Drupal\file\Entity\File::load($image_id);
              $uri = $image_file->uri->value;
              $facebook_image_url = Drupal\image\Entity\ImageStyle::load('your_facebook_style')->buildUrl($uri);
              $facebook_metatag = [
                  '#tag' => 'meta',
                  '#attributes' => [
                    'property' => 'og:image',
                    'content' => $image_url,
                  ],
                ];
               $build['#attached']['html_head'][] = [$facebook_metatag, 'facebook_metatag'];
// the same for other social networks:

$twitter_image_url = Drupal\image\Entity\ImageStyle::load('your_twitter_style')->buildUrl($uri);
//etc
                  break;
              
          }
        
      }
    
    }

And you get this metatag type meta property="og:image" content="http://static01.nyt.com/images/2015/02/19/arts/international/19iht-btnumbers19A/19iht-btnumbers19A-facebookJumbo-v2.jpg"

It seems you want to generate proper metatags for your node pages (blogs). To generate them dynamically i propose to add to your module.module file next code with hook_entity_view function:

  function your_module_entity_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {

  if ($entity->getEntityTypeId() == 'node') {
      $bundle = $entity->bundle();
      switch ($bundle){
          case 'blog':
              $image = $entity->get('field_image');
              $image_id = $image->getValue()[0]['target_id'];
              $image_file = \Drupal\file\Entity\File::load($image_id);
              $uri = $image_file->uri->value;
              $facebook_image_url = Drupal\image\Entity\ImageStyle::load('your_facebook_style')->buildUrl($uri);
              $facebook_metatag = [
                  '#tag' => 'meta',
                  '#attributes' => [
                    'property' => 'og:image',
                    'content' => $image_url,
                  ],
                ];
               $build['#attached']['html_head'][] = [$facebook_metatag, 'facebook_metatag'];
// the same for other social networks:

$twitter_image_url = Drupal\image\Entity\ImageStyle::load('your_twitter_style')->buildUrl($uri);
//etc
                  break;
              
          }
        
      }
    
    }

And you get this metatag type meta property="og:image" content="http://static01.nyt.com/images/2015/02/19/arts/international/19iht-btnumbers19A/19iht-btnumbers19A-facebookJumbo-v2.jpg" Also you can add any metatag in such a manner:

 $facebook_metatag = [
    '#tag' => 'meta',
    '#attributes' => [
             'property' => 'og:title',
             'content' => $your_node_title,
          ],
   ];
   $build['#attached']['html_head'][] = [$facebook_metatag, 'facebook_metatag'];
deleted 9 characters in body
Source Link
Andrew Nim
  • 865
  • 4
  • 10

It seems you want to generate proper metatags for your node pages (blogs). To generate them dynamically i propose to add to your module.module file next code with hook_entity_view function:

  function your_module_entity_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {

  if ($entity->getEntityTypeId() == 'node') {
      $bundle = $entity->bundle();
      switch ($bundle){
          case 'blog':
              $image = $entity->get('field_image');
              $image_id = $image->getValue()[0]['target_id'];
              $image_file = \Drupal\file\Entity\File::load($image_id);
              $uri = $image_file->uri->value;
              $facebook_image_url = Drupal\image\Entity\ImageStyle::load('your_facebook_style')->buildUrl($uri);
              $facebook_metatag = [
                  '#tag' => 'meta',
                  '#attributes' => [
                    'property' => 'og:image',
                    'content' => $image_url,
                  ],
                ];
               $build['#attached']['html_head'][] = [$facebook_metatag, 'facebook_metatag'];
// the same for other social networks:

$twitter_image_url = Drupal\image\Entity\ImageStyle::load('your_twitter_style')->buildUrl($uri);
//etc
                  break;
              
          }
        
      }
    
    }

And you get this metatag type  meta property="og:image" content="http://static01.nyt.com/images/2015/02/19/arts/international/19iht-btnumbers19A/19iht-btnumbers19A-facebookJumbo-v2.jpg"

It seems you want to generate proper metatags for your node pages (blogs). To generate them dynamically i propose to add to your module.module file next code with hook_entity_view function:

  function your_module_entity_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {

  if ($entity->getEntityTypeId() == 'node') {
      $bundle = $entity->bundle();
      switch ($bundle){
          case 'blog':
              $image = $entity->get('field_image');
              $image_id = $image->getValue()[0]['target_id'];
              $image_file = \Drupal\file\Entity\File::load($image_id);
              $uri = $image_file->uri->value;
              $facebook_image_url = Drupal\image\Entity\ImageStyle::load('your_facebook_style')->buildUrl($uri);
              $facebook_metatag = [
                  '#tag' => 'meta',
                  '#attributes' => [
                    'property' => 'og:image',
                    'content' => $image_url,
                  ],
                ];
               $build['#attached']['html_head'][] = [$facebook_metatag, 'facebook_metatag'];
// the same for other social networks:

$twitter_image_url = Drupal\image\Entity\ImageStyle::load('your_twitter_style')->buildUrl($uri);
//etc
                  break;
              
          }
        
      }
    
    }

And you get this metatag type  

It seems you want to generate proper metatags for your node pages (blogs). To generate them dynamically i propose to add to your module.module file next code with hook_entity_view function:

  function your_module_entity_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {

  if ($entity->getEntityTypeId() == 'node') {
      $bundle = $entity->bundle();
      switch ($bundle){
          case 'blog':
              $image = $entity->get('field_image');
              $image_id = $image->getValue()[0]['target_id'];
              $image_file = \Drupal\file\Entity\File::load($image_id);
              $uri = $image_file->uri->value;
              $facebook_image_url = Drupal\image\Entity\ImageStyle::load('your_facebook_style')->buildUrl($uri);
              $facebook_metatag = [
                  '#tag' => 'meta',
                  '#attributes' => [
                    'property' => 'og:image',
                    'content' => $image_url,
                  ],
                ];
               $build['#attached']['html_head'][] = [$facebook_metatag, 'facebook_metatag'];
// the same for other social networks:

$twitter_image_url = Drupal\image\Entity\ImageStyle::load('your_twitter_style')->buildUrl($uri);
//etc
                  break;
              
          }
        
      }
    
    }

And you get this metatag type meta property="og:image" content="http://static01.nyt.com/images/2015/02/19/arts/international/19iht-btnumbers19A/19iht-btnumbers19A-facebookJumbo-v2.jpg"

Source Link
Andrew Nim
  • 865
  • 4
  • 10
Loading