Metatags generated from views results I'm using the Metatag module to include appropriate Open Graph, etc. tags to delineate site content as it is shared on social media sites. The front page of our site is a Views Page, feature only the most recent piece of content. We would like some of the info from this featured node to be included in the meta tags for the home page of the site.

What I'm wondering is -- How can I include meta tags specific to the first result from a View?

Alternately, can anyone suggest an alternative approach to either featuring the most recent piece of content on the home page that would solve this problem?

Thanks!
Found this thread, which was very helpful:

Metatags and Commerce - pass taxonomy metatags to commerce product view

I adapted that approach to have metatag generate the tags from the first entity returned by the view:

/* 
 * Implement HOOK_views_post_render to run code for each view render
 */ 
function THEME_OR_MODULE_views_post_render(&amp;$view, &amp;$output, &amp;$cache) {
  // check for a particular view and view display page
  if ($view-&gt;name=='YOUR_VIEW' &amp;&amp; $view-&gt;current_display == 'YOUR_VIEW_DISPLAY') {

    // retrieve the first node in the view
    $entity_type = 'node';
    $entity = entity_load($entity_type, $view-&gt;result[0]-&gt;nid);
    $language = entity_language($entity_type,$entity);

    // Generate metatags output
    if ($tags = metatag_generate_entity_metatags($entity, $entity_type, $language, 'YOUR_ENTITY_DISPLAY_MODE')) {
      list($entity_id, $revision_id, $bundle) = entity_extract_ids($entity_type, $entity);
      $instance = "{$entity_type}:{$bundle}";

      // register the term's metatags
      metatag_page_set_metatags($instance, $tags);
    }
  }
}


Here is alternate code which doesn't rely on the Metatag module, and allows for more finely tailored meta tags based on view results:

function HOOK_preprocess_html(&amp;$vars) {

    // only operate on the front page
    if ($vars['is_front']) {

        // get the view results
        $view_results = views_get_view_result('YOUR_VIEW_NAME','YOUR_VIEW_DISPLAY_NAME');
        // load up the first node
        $node = entity_metadata_wrapper('node',$view_results[0]-&gt;_field_data['nid']['entity']);

        // get some data
        $title = $node-&gt;label();

        // some fields may require more processing
        $description = trim(drupal_html_to_text($node-&gt;field_description-&gt;value()['safe_value']));
        $image = image_style_url('YOUR_IMAGE_STYLE',$film-&gt;field_image-&gt;value()['uri']);

        // generate and output the meta tags
        $tag = array(
        '#type' =&gt; 'html_tag',
        '#tag' =&gt; 'meta',
        '#attributes' =&gt; array(
          'property' =&gt;  'og:title',
          'content' =&gt; $title,
        )
        );
      drupal_add_html_head($tag, 'og_title');

        $tag = array(
        '#type' =&gt; 'html_tag',
        '#tag' =&gt; 'meta',
        '#attributes' =&gt; array(
          'property' =&gt;  'og:description',
          'content' =&gt; $description,
        )
        );
      drupal_add_html_head($tag, 'og_description');

        $tag = array(
        '#type' =&gt; 'html_tag',
        '#tag' =&gt; 'meta',
        '#attributes' =&gt; array(
          'property' =&gt;  'og:image',
          'content' =&gt; $image,
        )
        );
      drupal_add_html_head($tag, 'og_image');
    }
}