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:
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:
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
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
Thx for the help. Itās ok for me now !
Smashing
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();
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() : ' ',
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
Great Minds
Thanks both! 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