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 :
<!-- 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 !