Newbie question: How to configure the Meta Tags Plugin by pedroborges

Hi all!
Still in my first steps in Kirby, I successfully installed the Meta Tags Plugin by Pedro Borges. In the header.php snippet, I included <?php echo $page->metaTags() ?> like suggested in the documentation.
Whatever I include in /site/config.php, I get only the default og meta tags. Could someone show me an example of the /site/config.php where more than the og tags are enabled, e.g. twitter cards?
Here is my config.php - what do I wrong?

return [
    'debug' => true,
];

return [
    'afbora.kirby-minify-html.enabled' => true,
    'afbora.kirby-minify-html.options' => [
        'doOptimizeViaHtmlDomParser' => true, // set true/false or remove line to default
        'doRemoveSpacesBetweenTags'  => false // set true/false or remove line to default
    ],
];

return [
    'debug' => true,
    'smartypants' => true,
    'markdown' => [
        'extra' => true
        ]
        ];
        
return [
    // other options...
    'pedroborges.meta-tags.default' => function ($page, $site) {
        return [
            'title' => $site->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()
            ]
        ];
    }
];

You have too many return statemements, and a couple of duplicate settings. It should be all in one:

return [
  'debug' => true,
  'smartypants' => true,
  'markdown' => [
      'extra' => true
      ],



    'afbora.kirby-minify-html.enabled' => true,
    'afbora.kirby-minify-html.options' => [
        'doOptimizeViaHtmlDomParser' => true, // set true/false or remove line to default
        'doRemoveSpacesBetweenTags'  => false // set true/false or remove line to default
    ],


        

    // other options...
    'pedroborges.meta-tags.default' => function ($page, $site) {
        return [
            'title' => $site->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()
            ]
        ];
    }
];

great, thanks - this is now working. I will start playing a bit :slight_smile:

Just for some background information, because this is important to understand (and is nothing Kirby specific): A PHP return statement stops the execution of the current script/function and returns the control to the calling script. Therefore, multiple successive return statements without conditions in the config/or any other script have no effect at all.

https://www.php.net/manual/de/function.return.php

On a side note: It pays off to use a good PHP editor that tells you when things go wrong in your code.

1 Like

thanks much – there’s still a lot to learn for me. I come from the content development/UX/marketing side, and until now mostly worked with WP although I’m tired of WPs shortcoming, so I try Kirby for my business website

I’m on BBEdit/Mac, if this okay?

That will allow you to edit php just fine, but something like https://www.jetbrains.com/phpstorm/ will give you super powers. (I use Atom with the IDE and PHP extensions).

It really depends what you want - as a hobbyist, BBEdit will do just fine, but its harder to trace issues because its not aware of the bigger picture, how all the PHP files hang together.

That is very true, PHPStorm really helps you write better code, but the price tag is probably a bit too high for non-professional use.

Before I switched to PHPStorm is used VS Code with PHP extensions, which worked well enough, but of course doesn’t give you the same powers unless you go for a paid add-on.

I have never used BBEdit, but if it comes with PHP syntax checking natively or via an add-one, you will be fine.

1 Like

Its neat. I used TextWrangler too, its little brother, for years. I miss it. They axed it :frowning:

2 Likes

I would hardly give up BBEdit … reliable since 20+ years. Must check if there’s a PHP syntax checker available, though.
Happy about your pro tips, thank you!

Ill be switching to OniVim2 when they finally put a Beta out (I backed it over a year ago… its been a long road). Its already blinding fast (unlike Atom which can be like typying through treacle at times)

Itll be compatable with VSCode extenstions, so in theory you can turn it into a PHP IDE with the right extensions.

https://www.onivim.io/

By the way: We have a new Kirbycast channel:

https://www.youtube.com/kirbycasts

The first two intro videos are already online, more will follow in the coming days/weeks.

2 Likes

Dear all,
since I did all the changes in the config.php that you have suggested, the e-mail form isn’t working anymore. I can’t see a syntax error or typo. Do you see one?

return [
  'debug' => true,
  'smartypants' => true,
  'markdown' => [
      'extra' => true
      ],

  'email' => [
    'transport' => [
      'type' => 'smtp',
      'host' => 'smtpserver',
      'port' => 587,
      'security' => true,
      'auth' => true,
      'username' => 'xxxx',
      'password' => 'xxxx',
    ]
  ],

    'afbora.kirby-minify-html.enabled' => true,
    'afbora.kirby-minify-html.options' => [
        'doOptimizeViaHtmlDomParser' => true, // set true/false or remove line to default
        'doRemoveSpacesBetweenTags'  => false // set true/false or remove line to default
    ],


        
    'pedroborges.meta-tags.default' => function ($page, $site) {
        return [
            'title' => $site->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',
								'site' => $site->twitter(),
								'title' => $page->title()// ,
						//     'namespace:image' => function ($page) {
						//         $image = $page->cover()->toFile();
						// 
						//         return [
						//             'image' => $image->url(),
						//             'alt' => $image->alt()
						//         ];
						//     }
						]
        ];
    }
];

Since your post is marked as the solution, I assume this is fixed?

Blockquote[quote=“texnixe, post:13, topic:19323, full:true”]
Since your post is marked as the solution, I assume this is fixed?
[/quote]

oh … no, it’s not fixed yet. The ‘solution’ checkbox was a stupid mistake, sorry me.

And your email worked before you adapted the config?

yes, it was working before – so I really don’t understand

The config looks ok, apart from the missing <?php tag at the beginning of the file but since you are not getting text output on the page, I assume it is present?

yes, the start is <?php

even when I delete all except the ‘email’ part, it’s not working anymore, neither on my local server nor on the webserver in its development area.

Hm, there are no syntax errors in the file. Do you get any error messages? Does $kirby->email() return true? Maybe the mail doesn’t get through do to some blacklisting issues? Is that a mailing service you use?