# Most elegant way to do meta data (facebook, twitter, google)

**URL:** <https://forum.getkirby.com/t/most-elegant-way-to-do-meta-data-facebook-twitter-google/9719>\
**Category:** Questions\
**Tags:** v2\
**Created:** [February 14, 2018, 1:11pm UTC](https://forum.getkirby.com/t/most-elegant-way-to-do-meta-data-facebook-twitter-google/9719 "2018-02-14T13:11:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stef](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/stef/32/5109_2.png) [@stef](https://forum.getkirby.com/u/stef)\
**Post date:** [February 14, 2018, 1:11pm UTC](https://forum.getkirby.com/t/most-elegant-way-to-do-meta-data-facebook-twitter-google/9719/1 "2018-02-14T13:11:02Z")

</div>

What is the most elegant data to do the meta tags?  
for facebook I have this for example

```
  <meta property="og:title" content="<?php echo $page->title() ?> | <?php echo $site->title() ?>"</title>
  <meta property="og:description" content="<?php echo $page->text()->short(100) ?> <?= $site->description() ?>"/>
  <meta property="og:image" content="<?php echo $page->images()->first(); ?>"/>

```

---

<div class="post-metadata">

**Author:** ![pedroborges](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/pedroborges/32/7038_2.png) [@pedroborges](https://forum.getkirby.com/u/pedroborges)\
**Post date:** [February 14, 2018, 1:22pm UTC](https://forum.getkirby.com/t/most-elegant-way-to-do-meta-data-facebook-twitter-google/9719/2 "2018-02-14T13:22:47Z")

</div>

The Meta Tags plugin may help you:

> **[pedroborges/kirby-meta-tags](https://github.com/pedroborges/kirby-meta-tags)**
>
> kirby-meta-tags - HTML meta tags generator for Kirby. Supports Open Graph and Twitter Cards out of the box.

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [February 14, 2018, 2:44pm UTC](https://forum.getkirby.com/t/most-elegant-way-to-do-meta-data-facebook-twitter-google/9719/3 "2018-02-14T14:44:00Z")

</div>

Yup, the Meta Tags plugin is the way to go (its awesome 🙂 ), combined with some shared global fields on every page. I went into detail in [this post](https://forum.getkirby.com/t/different-titles-for-navigation-and-title-tag/9540/5?u=jimbobrjames) a few days ago.

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [February 14, 2018, 2:49pm UTC](https://forum.getkirby.com/t/most-elegant-way-to-do-meta-data-facebook-twitter-google/9719/4 "2018-02-14T14:49:45Z")

</div>

As a bonus, heres the meta tags plugin config i’m using on my website, complete with fallback imagery for sharing on twitter and facebook. Just pop fallback image in your `assets/images` folder.

```auto
$image = new Asset('assets/images/twitter-share.jpg');
$image = new Asset('assets/images/facebook-share.jpg');

```

It checks the current page for a share image. If the field is empty, it falls back to checking the site page for a share image. If the worst happens, and thats also empty, it falls back to a generic share image from the assets folder.

Makes use of the [focusCrop plugin](https://github.com/flokosiol/kirby-focus) incase the image is larger the the share dimensions.

Enjoy 🙂

```auto
c::set('meta-tags.default', function(Page $page, Site $site) {
    return [
        'title' => $page->isHomePage()
          ? $site->seotitle()
          : $page->seotitle().' | '.$site->seotitle(),
          'meta' => [
              'robots' => 'index,follow,noodp',
              'description' => $page->isHomePage()
                ? $site->seometa()
                : $page->seometa(),
              'keywords' => $page->isHomePage()
                ? $site->seokeywords()
                : $page->seokeywords(),
              'robots' => 'index,follow,noodp',
          ],
        'link' => [
            'canonical' => $page->url()
        ],
        'og' => [
            'title' => $page->isHomePage()
                ? $site->seotitle()
                : $page->seotitle().' | '.$site->seotitle(),
            'type' => 'website',
            'site_name' => $site->title(),
            'url' => $page->url(),

            'image' => function ($page) {
                $image = $page->shareimagefacebook()->toFile();
                if ($image) {
                    return $image->focusCrop(1200, 630)->url();
                } else {
                    $image = site()->shareimagefacebook()->toFile();
                    if ($image) {
                        return $image->focusCrop(1200, 630)->url();
                    } else {
                        $image = new Asset('assets/images/facebook-share.jpg');
                        return $image->url();
                    }
                }
            },

            'description' => $page->isHomePage()
                ? $site->seometa()
                : $page->seometa().' | '.$site->seotitle(),
        ],
        'twitter' => [
            'title' => $page->isHomePage()
                ? $site->seotitle()
                : $page->seotitle().' | '.$site->seotitle(),
            'card' => 'summary',
            'site' => $site->twitterusername(),
            'creator' => $site->twitterhandle(),
            'image' => function ($page) {
                $image = $page->shareimagetwitter()->toFile();
                if ($image) {
                    return $image->focusCrop(1024, 512)->url();
                } else {
                    $image = site()->shareimagetwitter()->toFile();
                    if ($image) {
                        return $image->focusCrop(1024, 512)->url();
                    } else {
                        $image = new Asset('assets/images/twitter-share.jpg');
                        return $image->url();
                    }
                }
            },
            'url' => $page->url(),
            'description' => $page->isHomePage()
                ? $site->seometa()
                : $page->seometa().' | '.$site->seotitle(),
        ]
    ];
}); 

```

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:30pm UTC](https://forum.getkirby.com/t/most-elegant-way-to-do-meta-data-facebook-twitter-google/9719/5 "2025-02-06T17:30:04Z")

</div>

Archived on February 6, 2025, 5:30pm UTC


