0

I am trying to create WebSite schema condition output in html.tpl.php in Drupal 7, so installed schema.org module, but it doesn't come with all the fields that my project required, for example, description. How do I get the description value from "admin/config/search/metatags/config/global%3Afrontpage"?

What I have so far.

<?php if(drupal_is_front_page()) {
$logoSchema = theme_get_setting('logo');
$urlSchema = $GLOBALS['base_url'];
echo '
<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "WebSite",
  "url": "'. $urlSchema .'",
  "name": "Company Name, Inc.",
  "image": "'. $logoSchema .'",
  "description": "**NEED HELP GETTING THE VALUE**",
  "potentialAction": {
    "@type": "SearchAction",
    "target": "'. $urlSchema .'/search/{search_term_string}",
    "query-input": "required name=search_term_string"
  }
}
</script>';
} ?>
</head>

1 Answer 1

0
  1. create a preprocess_html function in template.php

    function porto_sub_preprocess_html(&$vars){
      if (drupal_is_front_page()) {
        if (isset($vars['page']) && isset($vars['page']['content']) && isset($vars['page']['content']['metatags'])) {
          $meta_tags = $vars['page']['content']['metatags'];
          if (isset($meta_tags['global:frontpage']) && isset($meta_tags['global:frontpage']['description'])) {
            $meta_desc_list = $meta_tags['global:frontpage']['description'];
            if (isset($meta_desc_list['#attached']) && isset($meta_desc_list['#attached']['drupal_add_html_head'])) {
              if (isset($meta_desc_list['#attached']['drupal_add_html_head'][0]) && isset($meta_desc_list['#attached']['drupal_add_html_head'][0][0])) {
                if ($meta_desc_list['#attached']['drupal_add_html_head'][0][0]['#value']) {
                  $vars['front_page_meta_desc'] = $meta_desc_list['#attached']['drupal_add_html_head'][0][0]['#value'];
                }
              }
            }
          }
        }
      }
      drupal_add_http_header('Cache-Tag','mktg',true);
    

 
2. This defined meta tag is accessible from html.tpl.php

 if (!isset($front_page_meta_desc)) {
       $front_page_meta_desc = '';
     }

In the schema JSONLD, you need to call the variable.

"description": "' . $front_page_meta_desc . '",

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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