Templates


Twig
{% set ogImage = craft.placard.shareImageUrl(entry ?? null) %}
{% if ogImage %}
    <meta property="og:image" content="{{ ogImage }}">
{% endif %}
Helper Returns
shareImageUrl(entry) The image the entry shares (its Social Image field's choice, else the first image in imageFieldHandles, else the card). Anything that isn't an entry gets default()
previewImageUrl(entry) As shareImageUrl(), but the card also renders drafts for logged-in users. For the CP, like a field layout's Template element (craft.placard.previewImageUrl(element)), not front-end templates
entryHasImage(entry) Whether that's one of the entry's own images
url(entry) The card's URL. Only live entries with a URL are served, so drafts and entries without a page (nested entries, sections without URLs) can't be read from it
default() defaultImagePath, for pages with no entry, or null when it isn't set

With SEOmatic or SEOmate #

With SEOmatic or SEOmate installed, Placard gives it each entry's share image. There's nothing to add to your templates: their og:image and twitter:image tags show the Social Image field's choice, or the card.

  • SEOmatic gets it as the entry's SEO, Open Graph and X image, replacing the images its section settings choose. Pages that aren't entries keep SEOmatic's own.
  • SEOmate gets it as image, og:image and twitter:image, as though your layout had set them in the seomate variable. A template that sets seomate.meta.image itself keeps its own. Pages that aren't entries keep SEOmate's own.

Cards are already 1200×630, so neither plugin resizes them. With SEOmatic, use the summary_large_image X card so they show at full size.

Set imageFieldHandles to the image fields your SEO plugin used, so entries without a Social Image field share the same image as before. Placard reads paths like seo.seoImage, but not SEOmate's field.type:subField form.

To pass the image yourself instead, set 'seoPlugins' => false, then use craft.placard.shareImageUrl() wherever you like.