# Title customization with Pedro Borges meta tags plugin

**URL:** <https://forum.getkirby.com/t/title-customization-with-pedro-borges-meta-tags-plugin/17723>\
**Category:** Questions\
**Tags:** v3\
**Created:** [March 29, 2020, 10:14pm UTC](https://forum.getkirby.com/t/title-customization-with-pedro-borges-meta-tags-plugin/17723 "2020-03-29T22:14:13Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![cameronmoll](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/cameronmoll/32/11649_2.png) [@cameronmoll](https://forum.getkirby.com/u/cameronmoll)\
**Post date:** [March 29, 2020, 10:14pm UTC](https://forum.getkirby.com/t/title-customization-with-pedro-borges-meta-tags-plugin/17723/1 "2020-03-29T22:14:13Z")

</div>

Hi friends,

Disclaimer: I know very little PHP 🙂

I’m using Pedro Borges’ meta tags plugin. This is what I have in /site/config/config.php:

```
<?php

return [
    'debug' => true,
    'smartypants' => true,
    'markdown' => [
        'extra' => true
        ],
    'pedroborges.meta-tags.default' => function ($page, $site) {
        return [
            'title' => $page->isHomePage() ? site()->title() : $page->title(),
            'meta' => [
                'description' => $site->description()
            ],
            'link' => [
                'canonical' => $page->url()
            ],
            'og' => [
                'title' => $page->isHomePage()
                    ? $site->title()
                    : $page->title(),
                'type' => 'website',
                'site_name' => $site->title(),
                'url' => $page->url()
            ],
            'twitter' => [
			    'card' => 'summary_large_image',
			    'site' => $site->twitter(),
			    'title' => $page->title()
		]
        ];
    }
];

```

Currently this returns “Cameron Moll” as the for every page on my site. I would like the homepage to have the title “Cameron Moll” and then every other page to be “[page title] – Cameron Moll”.

How can I configure this?

P.S. please tell me if anything else looks amiss!

---

<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:** [March 29, 2020, 11:30pm UTC](https://forum.getkirby.com/t/title-customization-with-pedro-borges-meta-tags-plugin/17723/2 "2020-03-29T23:30:50Z")

</div>

Hm, what you posted above should actually work, with only the little addition that you add the site title after the page title:

```auto
'title' => $page->isHomePage()
    ? $site->title()
    : $page->title() . ' - ' . $site->title(),

```

---

<div class="post-metadata">

**Author:** ![cameronmoll](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/cameronmoll/32/11649_2.png) [@cameronmoll](https://forum.getkirby.com/u/cameronmoll)\
**Post date:** [March 30, 2020, 11:45am UTC](https://forum.getkirby.com/t/title-customization-with-pedro-borges-meta-tags-plugin/17723/3 "2020-03-30T11:45:40Z")

</div>

Beautiful. Thank you!

---

<div class="post-metadata">

**Author:** ![cameronmoll](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/cameronmoll/32/11649_2.png) [@cameronmoll](https://forum.getkirby.com/u/cameronmoll)\
**Post date:** [March 31, 2020, 2:23pm UTC](https://forum.getkirby.com/t/title-customization-with-pedro-borges-meta-tags-plugin/17723/4 "2020-03-31T14:23:12Z")

</div>

@texnixe – how can I add a description to the OG and Twitter cards in the code at the top of this post?

When I add `'description' => $site->description()` to either card it breaks my site.

---

<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:** [March 31, 2020, 2:27pm UTC](https://forum.getkirby.com/t/title-customization-with-pedro-borges-meta-tags-plugin/17723/5 "2020-03-31T14:27:57Z")

</div>

> [@cameronmoll](#):
>
> it breaks my site.

What exactly did you add where and what is the error message. Could you please post the code that breaks the page?

---

<div class="post-metadata">

**Author:** ![cameronmoll](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/cameronmoll/32/11649_2.png) [@cameronmoll](https://forum.getkirby.com/u/cameronmoll)\
**Post date:** [March 31, 2020, 2:49pm UTC](https://forum.getkirby.com/t/title-customization-with-pedro-borges-meta-tags-plugin/17723/6 "2020-03-31T14:49:19Z")

</div>

Of course, now I can’t replicate it breaking 🙂

In /site/config/config.php here’s the code I’ve added for description:

```
return [
    'debug' => true,
    'smartypants' => true,
    'markdown' => [
        'extra' => true
        ],
    'pedroborges.meta-tags.default' => function ($page, $site) {
        return [
            'title' => $page->isHomePage()
				? $site->title()
				: $page->title() . ' - ' . $site->title(),
            'meta' => [
                'description' => $site->description()
            ],
            'link' => [
                'canonical' => $page->url()
            ],
            'og' => [
				'title' => $page->isHomePage()
					? $site->title()
					: $page->title() . ' - ' . $site->title(),
				'description' => $site->description(),
                'type' => 'website',
                'site_name' => $site->title(),
                'url' => $page->url()
            ],
            'twitter' => [
			    'card' => 'summary_large_image',
			    'site' => $site->twitter(),
				'title' => $page->isHomePage()
					? $site->title()
					: $page->title() . ' - ' . $site->title(),
				'description' => $site->description()
		]
        ];
    }
];

```

However no description is returned in the HTML:

```
<meta property="og:title" content="A Beginner&rsquo;s Guide to Mental Health &amp; Mental Illness - Cameron Moll">
<meta property="og:type" content="website">
<meta property="og:site_name" content="Cameron Moll">
<meta property="og:url" content="http://cm.test/journal/beginners-guide-to-mental-health">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="A Beginner&rsquo;s Guide to Mental Health &amp; Mental Illness - Cameron Moll">
<link rel="canonical" href="http://cm.test/journal/beginners-guide-to-mental-health">
<meta name="twitter:image" content="http://cm.test/media/pages/journal/beginners-guide-to-mental-health/2463091230-1583186949/cameronmoll.jpg" />
<meta property="og:image" content="http://cm.test/media/pages/journal/beginners-guide-to-mental-health/2463091230-

```

In the plugin /site/plugins/feed/index.php I see this default code:

```
 // set all default values
            $defaults = [
                'url' => page()->url(),
                'title' => 'Feed',
                'description' => '',
                'link' => url(),
                'datefield' => 'date',
                'imgfield' => 'coverimage',
                'subfield' => 'subtitle',
                'textfield' => 'text',
                'modified' => time(),
                'excerpt' => true,
                'generator' => kirby()->option('feed.generator', 'Kirby'),
                'header' => true,
                'snippet' => false,
            ];

```

Notice the description value is blank. Does this have anything to do with it?

---

<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:** [March 31, 2020, 3:10pm UTC](https://forum.getkirby.com/t/title-customization-with-pedro-borges-meta-tags-plugin/17723/7 "2020-03-31T15:10:16Z")

</div>

> [@cameronmoll](#):
>
> ‘description’ =\> $site-\>description(),

Does `$site->description()` have any content? Looks like this is only rendered if not empty.

---

<div class="post-metadata">

**Author:** ![cameronmoll](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/cameronmoll/32/11649_2.png) [@cameronmoll](https://forum.getkirby.com/u/cameronmoll)\
**Post date:** [March 31, 2020, 3:34pm UTC](https://forum.getkirby.com/t/title-customization-with-pedro-borges-meta-tags-plugin/17723/8 "2020-03-31T15:34:35Z")

</div>

Good point. With each blog post I include an intro (summary). This is called in the panel:

```
intro:
    type: editor
    size: large

```

And then on the blog home page it’s rendered with `desc`:

`<?php snippet('notes', ['notes' => $page->children()->listed()->sortBy('date', 'desc')]) ?>`

I’d prefer `desc` be the description included in the OG and Twitter cards. (It’s more of a page description than site description.)

---

<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:** [March 31, 2020, 3:40pm UTC](https://forum.getkirby.com/t/title-customization-with-pedro-borges-meta-tags-plugin/17723/9 "2020-03-31T15:40:32Z")

</div>

Then you probably want to use the `intro` field for pages and the site descriptions on the homepage. Where is `desc` defined as a field, to me that looks more like youre are sorting in descending order (`desc`):

```auto
'description' => $page->isHomePage()
  ? $site->description() //if that field exists, otherwise replace with the field name that you use in the `site.yml` blueprint for the site's description.
  : $page->intro(),

```

---

<div class="post-metadata">

**Author:** ![cameronmoll](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/cameronmoll/32/11649_2.png) [@cameronmoll](https://forum.getkirby.com/u/cameronmoll)\
**Post date:** [March 31, 2020, 4:01pm UTC](https://forum.getkirby.com/t/title-customization-with-pedro-borges-meta-tags-plugin/17723/10 "2020-03-31T16:01:30Z")

</div>

Fantastic. Except it renders a lot of extra entities:

```
<meta property="og:description" content="[
    {
        &quot;attrs&quot;: [],
        &quot;content&quot;: &quot;Mental health and mental illness are tough subjects to talk about. This five-part series aims to ignite greater awareness of mental health issues at home and in the workplace, encourage more candid conversation on the topic, reduce the stigma associated with mental illness, and improve mental performance at home and in the workplace. Written for everyday people by everyday people.&quot;,
        &quot;id&quot;: &quot;_dorbiblbf&quot;,
        &quot;type&quot;: &quot;paragraph&quot;
    }
]">
```

---

<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:** [March 31, 2020, 4:07pm UTC](https://forum.getkirby.com/t/title-customization-with-pedro-borges-meta-tags-plugin/17723/11 "2020-03-31T16:07:52Z")

</div>

Ah, ok, that comes from the editor, because it stored the content in json, so you have to transform that properly.

```auto
$page->intro()->blocks()

```

---

<div class="post-metadata">

**Author:** ![cameronmoll](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/cameronmoll/32/11649_2.png) [@cameronmoll](https://forum.getkirby.com/u/cameronmoll)\
**Post date:** [March 31, 2020, 4:15pm UTC](https://forum.getkirby.com/t/title-customization-with-pedro-borges-meta-tags-plugin/17723/12 "2020-03-31T16:15:41Z")

</div>

Almost there! Still a few extra entities such as `&lt;p&gt;`

```
<meta property="og:description" content="&lt;p&gt;Mental health and mental illness are tough subjects to talk about. This five-part series aims to ignite greater awareness of mental health issues at home and in the workplace, encourage more candid conversation on the topic, reduce the stigma associated with mental illness, and improve mental performance at home and in the workplace. Written for everyday people by everyday people.&lt;/p&gt;
">

```

I don’t see anything in the editor that would be adding these entities:

 ![Screen Shot 2020-03-31 at 12.13.54 PM](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/e/e716c3314e632e1ea9410a57b4f3e805b9dc4feb.png)

---

<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:** [March 31, 2020, 4:26pm UTC](https://forum.getkirby.com/t/title-customization-with-pedro-borges-meta-tags-plugin/17723/13 "2020-03-31T16:26:32Z")

</div>

> [@cameronmoll](#):
>
> \<p\>

Because the block in this case is rendered as a paragraph. I’m not too familiar withe the block methods, because I haven’t used it that often, but I guess there is a way to output just the raw text.

It probably makes sense to only get the first block anyway.

```auto
$page->intro()->blocks()->first()->content()

```

---

<div class="post-metadata">

**Author:** ![cameronmoll](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/cameronmoll/32/11649_2.png) [@cameronmoll](https://forum.getkirby.com/u/cameronmoll)\
**Post date:** [March 31, 2020, 5:16pm UTC](https://forum.getkirby.com/t/title-customization-with-pedro-borges-meta-tags-plugin/17723/14 "2020-03-31T17:16:19Z")

</div>

Excellent. Thanks for all your help!
