# Meta data images for template

**URL:** <https://forum.getkirby.com/t/meta-data-images-for-template/26981>\
**Category:** Questions\
**Created:** [November 8, 2022, 7:50pm UTC](https://forum.getkirby.com/t/meta-data-images-for-template/26981 "2022-11-08T19:50:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![claraloustau](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/claraloustau/32/12322_2.png) [@claraloustau](https://forum.getkirby.com/u/claraloustau)\
**Post date:** [November 8, 2022, 7:50pm UTC](https://forum.getkirby.com/t/meta-data-images-for-template/26981/1 "2022-11-08T19:50:48Z")

</div>

Hello !  
Could anyone can help me with my code ? I want to specify different og:image for pages from template article than other pages.

This is my code :

```auto
  <!-- Social -->
  <meta property="og:title" content="<?= $site->title()->html() ?> | <?= $page->title()->html() ?>">
  <meta property="og:site_name" content="<?= $site->title()->html() ?>" />
  <meta property="og:description" content="<?= page('metas')->descr()->html() ?>" />
  <meta property="og:url" content="<?= $page->url() ?>" />
  <?php /* <meta property="og:locale" content="<?= $language->locale() ?>" />*/?>
  <?php if($page->template()!="article"): ?>
  <meta property="og:image" content="assets/images/imf-share-<?= kirby()->language() ? kirby()->language()->code() : 'fr' ?>.png" />
  <meta property="og:image:type" content="image/png">
  <meta property="og:image:width" content="1200">
  <meta property="og:image:height" content="630">
  <?php endif ?>
  <?php if($page->template()=="article"): ?>
    <?php $cover = $page->cover()->thumb(['width' => 1200, 'height' => 630, 'crop' => true])->url() ?>
    <meta property="og:image" content="<?= $cover ?>" />
    <meta property="og:image:type" content="image/jpg">
    <meta property="og:image:width" content="1200">
    <meta property="og:image:height" content="630">
  <?php endif ?>

```

When I try to post the link of an article on social media, the image is displayed in the preview but it does not work when I post it. Any idea ?  
Thank you !

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [November 8, 2022, 8:09pm UTC](https://forum.getkirby.com/t/meta-data-images-for-template/26981/2 "2022-11-08T20:09:46Z")

</div>

> [@claraloustau](#):
>
> When I try to post the link of an article on social media, the image is displayed in the preview but it does not work when I post it.

I don’t understand this sentence. What exactly does not work? Can you please try and rephrase?

---

<div class="post-metadata">

**Author:** ![claraloustau](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/claraloustau/32/12322_2.png) [@claraloustau](https://forum.getkirby.com/u/claraloustau)\
**Post date:** [November 9, 2022, 12:45pm UTC](https://forum.getkirby.com/t/meta-data-images-for-template/26981/3 "2022-11-09T12:45:09Z")

</div>

Hello Texnine

I mean the image is displayed when I paste the link of an article in a social media (in this case Linkedin, but obviously I guess it’s the same case everywhere) only in the editor (before published the post), but once published the image is no longer displayed there is only a gray square. And og:title, og:site\_name, og:description and og:url is working.

---

<div class="post-metadata">

**Author:** ![stffr](https://avatars.discourse-cdn.com/v4/letter/s/c89c15/32.png) [@stffr](https://forum.getkirby.com/u/stffr)\
**Post date:** [November 9, 2022, 2:13pm UTC](https://forum.getkirby.com/t/meta-data-images-for-template/26981/4 "2022-11-09T14:13:52Z")

</div>

Did you try different platforms to rule a problem with LinkedIn?  
Try here please: [https://www.opengraph.xyz](https://www.opengraph.xyz)

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [November 9, 2022, 7:02pm UTC](https://forum.getkirby.com/t/meta-data-images-for-template/26981/5 "2022-11-09T19:02:59Z")

</div>

Apart from that, your code is a bit repetitive. My suggestion:

```auto
<?php 
$ogImage = ($page->template->name() === 'article' && ($image = $page->cover())) ? 
    $image->thumb(['width' => 1200, 'height' => 630, 'crop' => true]) :
    asset('assets/images/imf-share-' . kirby()->language()->code() . '.png');
if ($ogImage): ?>

  <meta property="og:image" content="<?= $ogImage->url() ?>" />
  <meta property="og:image:type" content="<?= $ogImage->mime() ?>">
  <meta property="og:image:width" content="<?= $ogImage->width() ?>">
  <meta property="og:image:height" content="<?= $ogImage->height() ?>">
<?php endif ?>  

```

But one question: Is `cover` just a field or is that a model method that returns an image?
