My front page is a panel with several views inside of it (panes and blocks). The top pane is an image (it's a photo of the day) that is generated by a view (the view just shows the latest "daily image" uploaded).

I want to use that image as the Open Graph image for the front page. However, it's not available as a token and I obviously can't put in a static URL. For the heck of it, I tried [current-page:query:field_daily_photo:und:0:uri] but that didn't work.

If I leave it blank, it almost inevitably picks up a different image. Is there a way to specify that I want that image?

[edit] It looks like this issue may be somewhat related, but not a duplicate since that sounds like it's more of a request for front page overrides, which this module already has. (#1141346: Home Page/Views)

Comments

mrpeanut’s picture

Category: support » feature

Cross-posting from Reddit in case anyone stumbles across this and wants to do the same thing. zad370 answered my question.

So basically, you want to insert the following meta tag in your front page's header:

<meta property="og:image" content="http://www.example.com/images/some_daily_image.jpg" />

If you haven't enabled the PHP Filter module, please enable that first. Download and enable Image URL Formatter module.

Go to your Daily Photo view and under Fields, add field_daily_photo again. Select Exclude from display option. Make sure you change the Formatter option to Image URL.

Now go to the Header portion of the view, and add a new Global: Text Area field. Change Text Format to PHP Code and check "Use replacement tokens from the first row" option. Insert the following PHP code:

$element = array(
  '#tag' => 'meta',
  '#attributes' => array(
    'property' => 'og:image', 
    'content' => '[field_daily_photo_1]',
  ),
);
drupal_add_html_head($element, 'og-image');
damienmckenna’s picture

Status: Active » Closed (won't fix)

As feature requests go this is pretty specific, it isn't something that Metatag will provide so your example code is the best way of doing it. Thanks for sharing.

damienmckenna’s picture

Issue summary: View changes

Added related issue