Kirby SEO plugin

Just pushed out my own solution to generating meta tags for SEO and social media sharing.

Itā€™s great used in tandem with my schema plugin:

4 Likes

Hi,
I am a pb with plugin. Undefined variable: metatitle when Ć  add the snippet in the snippet header.
A solution ?

Welcome to the forum @morganpouco :slight_smile:

It sounds like you are missing a controller. You can read about these hereā€¦ https://getkirby.com/docs/guide/templates/controllers

To fix it, you need create a controller in site/contollers that matches the name of your templates. You need one for each template you have in site/templates.

So for default.php template, the controller will look something like this:

<?php

return function ($page, $kirby, $site) {

  // Meta
  $seo = $kirby->controller('seo' , compact('page', 'site', 'kirby'));

  // Override Meta Title
  $metatitle = $page->title().' | '.$site->title();

  // Pass through data
  $data = compact('metatitle');

  return a::merge($seo , $data);

};

This brings in the shared controller from the plugin and makes its variables available to the page template.

I hope that helps :slight_smile:

1 Like

Thx for the help. Itā€™s ok for me now ! :wink:

Smashing :slight_smile:

1 Like

Hi guys, i am very new to kirby and have trouble running the kirby3-seo plugin on the starterkit - there seems to be a problem with the ā€œalbum.tplā€ controller . A little help would be greatly appreciated:

Also - having trouble adding the tabs as described in the read me file - should the tab folders from the plugin be copied to the blueprints folder?

Is really just adding this sufficient or should i structure also the other tab for the Note-Content?

title: Note
tabs:

  # SEO META
  meta: tabs/seo/meta

Many thanks,
Ivan

Hey Izag,

you cannot have to return functions in the controller, you have to merge the stuff from the original album.php controller with the stuff that is required. for the plugin.

Thank you - may i ask for some more help how to merge them?=)

There is an example in the plugins documentation:

<?php

return function ($page, $kirby, $site) {

  // Meta
  $seo = $kirby->controller('seo' , compact('page', 'site', 'kirby'));

  // Override Meta Title
  $metatitle = $page->seotitle().' | '.$site->title();

  $data = compact('metatitle');

  return a::merge($seo, $data);

};

In your case, you have a gallery to pass through, so the controller should only contain this:

<?php

return function ($page, $kirby, $site) {

  // Meta
  $seo = $kirby->controller('seo' , compact('page', 'site', 'kirby'));

  $gallery = $page->images()->sortBy('sort');

  $data = compact('gallery');

  return a::merge($seo, $data);

};

Wow thank you so much for the quick reply! It worked!

Hello, Iā€™m a bit of a beginner dev and trying to get the ā€˜shareimageā€™ to come through. Not sure if Iā€™m doing this correctly?

Iā€™m just building a one-pager site, so this is my controllers/site.php:

<?php

return function ($page, $kirby, $site) {

  // Meta
  $seo = $kirby->controller('seo' , compact('page', 'site', 'kirby'));

  // Override Meta Title
  $metatitle    =   $site->title();
  $metadesc     =   $site->seometa();
  $metakeywords =   $site->seotags();
  $metaimage    =   $site->shareimage();

  $metatwcard   =   'summary';


  // Pass through data
  $data = compact(
    'metatitle',
    'metadesc',
    'metakeywords',
    'metaimage',
    'metatwcard'
  );

  return a::merge($seo , $data);

};
?>

Iā€™ve uploaded a test image into the panel under shareimage per the default yml, but the output when I try either $site->shareimage(); or $site->shareimage()->url(); are both:

<meta content="- share-image-test.png" property="og:image">

truncated, without the full urlā€¦ Any help would be appreciated. Thanks!

Okay sorry, should have spent an extra 5 mins delving ā€” I followed this thread: Image()->url only coming up broken

and now it outputs the full url with this instead

edit: need to check file exists as per below replies. donā€™t use below code.

  $metaimage    =   $site->shareimage()->toFile()->url();

:grimacing: Thanks for giving me brain dump spaceā€¦ Iā€™ll just leave this up in case anyone runs into this issueā€¦

No worries, glad you got it working. However, you should check the image physically exists before trying to use it:

$metaimage = $site->shareimage()->toFile() ? $site->shareimage()->toFile()->crop(1280, 720)->url() : ' ',
1 Like

Please donā€™t call URL (or any other class method) without making sure the object exists:

$metaimage    =   $site->shareimage()->toFile()? $site->shareimage()->toFile()->url() : '';

@jimbobrjames beat me to it :wink:

1 Like

Great Minds :slight_smile:

Thanks both! :slight_smile: Have changed it accordingly.

Hi,

how do I get meta description and title working with kirby-blogposts? I edited several files, but I donā€™t have this fields using the kirby backend.

Thanks & best regards,
ralf

You have to add the meta fields to your blog post blueprints, see the readme of the plugin: https://github.com/HashandSalt/kirby3-seo

2 Likes