Get thumbnail url of Item in head

Hi all!
I’m trying to add a facebook/twitter/etc. share image (= the first media thumbnail of an item, if available) as a meta tag to my section in my theme. I’m not so familiar with APIs or how to do this best and couldn’t figure this out, as I could only get my thumbnail images in show.phtml but would require the $item array in layout.phtml.
So basically that’s what I’m seeking for:

<meta name="twitter:image" property="og:image" content="https://...large-thumnail-image-of-item.jpg">';

This might be a dump question but maybe I’m just not understanding the PHP Api fully, don’t have much experience with APIs or Omeka S Theming so far.

Thanks for your help,

Pages in Omeka S are build kind of “inside out”: the inner content gets rendered first and then the layout is wrapped around it.

This means you don’t actually need to change the layout view to do what you’re trying to do. You can set meta tags from within the “inner” content (the show.phtml) and have it appear in the page <head>.

$this->headMeta()->setProperty('og:image', $thumbnailUrl);
$this->headMeta()->setName('twitter:image', $thumbnailUrl);

A side note: the Sharing module can automatically set OpenGraph tags, including the image tag, for you.

1 Like

This topic was automatically closed 250 days after the last reply. New replies are no longer allowed.