Drupal - populate meta data to head

0 votes
372 views
added Nov 26, 2019 in Drupal by lcjr Lieutenant (12,010 points)
<?php // Metatag for social media
  drupal_set_title($news_title);
  // <!-- Search Engine -->
  // <meta name="description" content="test">
  drupal_add_html_head(array(
    '#tag' => 'meta',
    '#attributes' => array(
      'name' => 'description',
      'content' => $news_desc
    ),
  ), 'description');
  // <meta name="image" content="URL_OF_IMG">
  if(!empty($news_img))
  $news_img = str_replace('http://','https://',$news_img);
  drupal_add_html_head(array(
    '#tag' => 'meta',
    '#attributes' => array(
      'name' => 'image',
      'content' => $news_img
    ),
  ), 'image');
  // <!-- Schema.org for Google -->
  // <meta itemprop="name" content="test">
  drupal_add_html_head(array(
    '#tag' => 'meta',
    '#attributes' => array(
      'itemprop' => 'name',
      'content' => $news_title
    ),
  ), 'itemprop-name');
  // <meta itemprop="description" content="test">
  drupal_add_html_head(array(
    '#tag' => 'meta',
    '#attributes' => array(
      'itemprop' => 'description',
      'content' => $news_desc
    ),
  ), 'itemprop-description');
  // <meta itemprop="image" content="URL_OF_IMG">
  if(!empty($news_img))
  $news_img = str_replace('http://','https://',$news_img);
  drupal_add_html_head(array(
    '#tag' => 'meta',
    '#attributes' => array(
      'itemprop' => 'image',
      'content' => $news_img
    ),
  ), 'itemprop-image');
  // <!-- Twitter -->
  // <meta name="twitter:card" content="summary">
  drupal_add_html_head(array(
    '#tag' => 'meta',
    '#attributes' => array(
      'name' => 'twitter:card',
      'content' => $news_desc
    ),
  ), 'twitter:card');
  // <meta name="twitter:title" content="test">
  drupal_add_html_head(array(
    '#tag' => 'meta',
    '#attributes' => array(
      'name' => 'twitter:title',
      'content' => $news_title
    ),
  ), 'twitter:title');
  // <meta name="twitter:description" content="test">
  drupal_add_html_head(array(
    '#tag' => 'meta',
    '#attributes' => array(
      'name' => 'twitter:description',
      'content' => $news_desc
    ),
  ), 'twitter:description');
  // <meta name="twitter:site" content="@lazacode">
  drupal_add_html_head(array(
    '#tag' => 'meta',
    '#attributes' => array(
      'name' => 'twitter:site',
      'content' => "@myedgeprop"
    ),
  ), 'twitter:site');
  // <meta name="twitter:image:src" content="URL_OF_IMG">
  if(!empty($news_img))
  $news_img = str_replace('http://','https://',$news_img);
  drupal_add_html_head(array(
    '#tag' => 'meta',
    '#attributes' => array(
      'name' => 'twitter:image:src',
      'content' => $news_img
    ),
  ), 'twitter:image:src');
  // <!-- Open Graph general (Facebook, Pinterest & Google+) -->
  // <meta name="og:title" content="test">
  drupal_add_html_head(array(
    '#tag' => 'meta',
    '#attributes' => array(
      'property' => 'og:title',
      'content' => $news_title
    ),
  ), 'og:title');
  // <meta name="og:description" content="test">
  drupal_add_html_head(array(
    '#tag' => 'meta',
    '#attributes' => array(
      'property' => 'og:description',
      'content' => $news_desc
    ),
  ), 'og:description');
  // <meta name="og:image" content="URL_OF_IMG">

  if(!empty($news_img))
  $news_img = str_replace('http://','https://',$news_img);

  drupal_add_html_head(array(
    '#tag' => 'meta',
    '#attributes' => array(
      'property' => 'og:image',
      'content' => $news_img
    ),
  ), 'og:image');
  // <meta name="og:url" content="THE_CURRENT_SHOWN_URL">
  drupal_add_html_head(array(
    '#tag' => 'meta',
    '#attributes' => array(
      'property' => 'og:url',
      'content' => url(current_path(), array('absolute' => TRUE))
    ),
  ), 'og:url');
  // <meta name="og:site_name" content="lazacode.org">
  drupal_add_html_head(array(
    '#tag' => 'meta',
    '#attributes' => array(
      'property' => 'og:site_name',
      'content' => "Edgeprop.my"
    ),
  ), 'og:site_name');
  // <meta name="og:type" content="article">
  drupal_add_html_head(array(
    '#tag' => 'meta',
    '#attributes' => array(
      'property' => 'og:type',
      'content' => "article"
    ),
  ), 'og:type');
?>

 

1 Response

0 votes
responded Nov 27, 2019 by lcjr Lieutenant (12,010 points)
<?php
  /*************************************************
  * 2019 LAND ROVER CONTEST
  **************************************************/
  $params["title"] = "Lan Rover Contest";
  $params["description"] = "WIN A land rover for your lifetime experience!";
  $params["keywords"] = "lr, defender, 110, station wagon, lazacode";
  seo_head_meta('lrcontest',$params);
  $metaImg = 'https://xxxxxxx.cloudfront.net/lrcontest/meta.jpg';
  $ewfUrl = 'YOUR_SITE_URL';

   drupal_add_html_head(array(
    '#tag' => 'meta',
    '#attributes' => array(
      'property' => 'og:image',
      'content' => $metaImg
    ),
  ), 'image');

  drupal_add_html_head(array(
    '#tag' => 'meta',
    '#attributes' => array(
      'property' => 'og:url',
      'content' => $ewfUrl
    ),
  ), 'url');

  drupal_add_html_head(array(
    '#tag' => 'meta',
    '#attributes' => array(
      'property' => 'og:type',
      'content' => 'website'
    ),
  ), 'type');

  drupal_add_html_head(array(
    '#tag' => 'meta',
    '#attributes' => array(
      'property' => 'og:title',
      'content' => 'Defender Contest | Lazacode.org'
    ),
  ), 'title');

  drupal_add_html_head(array(
    '#tag' => 'meta',
    '#attributes' => array(
      'property' => 'og:description',
      'content' => 'WIN A land rover for your lifetime experience!'
    ),
  ), 'description');

  
?>

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...