if you have a regular landing page, ie., you are using with laravel, then make you initial page seo. All pages on a site doesn't have to be seo. Just suggestion.
Statamic + SEO
Hey, I am working on a Statamic project for the first time, a basic portfolio type website. I must say that it was a blast learning and working with it. The course learn Statamic with Jack was very helpful of course.
However I've been wondering how to configure SEO, without using an add-on? I tried googling some solutions, however not much out there, or my googling needs improvement.
Any suggestion/idea will be of great help. Thanks.
@jlrdw thanks for your suggestion. I am definitively not a SEO whizz, so not sure if I am doing this correctly.
This is working, and it's providing the categories sitemap and how I've handled this so far, of course I need to add static pages and other collections (I used Jack McDade basic meta options), I am still working on the sitemap, using the following as some guide (https://github.com/spatie/laravel-sitemap) and (https://laravel-news.com/laravel-automatic-sitemap) including the sitemap options...
Any suggestions, or thoughts of maybe improving this setup are greatly appreciated.
title: SEO
fields:
-
handle: meta_title
field:
type: text
display: Title
localizable: false
-
handle: meta_description
field:
type: textarea
display: Description
localizable: false
-
handle: meta_keywords
field:
type: taggable
display: Keywords
localizable: false
-
The head setup in layout.antlers
<title>{{ meta_title ?? title }}</title>
{{ if meta_description }}
<meta name="description" content="{{ meta_description }}" />
{{ /if }} {{ if meta_keywords }}
<meta name="keywords" content="{{ meta_keywords | join(', ') }}" />
{{ /if }}
The Sitemap logic that I added in the Controllers folder with the Sitemap fieldset options.
title: Sitemap
fields:
-
handle: sitemap
field:
options:
-
key: 'true'
value: Include
-
key: 'false'
value: Exclude
-
key: default
value: 'Use default'
default: default
type: button_group
display: Sitemap
localizable: false
-
handle: meta_priority
field:
type: float
display: Priority
localizable: false
width: 50
-
handle: change_frequency
field:
options:
-
key: daily
value: Daily
-
key: always
value: Always
-
key: hourly
value: Hourly
-
key: weekly
value: Weekly
-
key: yearly
value: Yearly
-
key: default
value: 'Use default'
-
key: monthly
value: Monthly
default: default
type: select
display: 'Change frequency'
localizable: false
width: 50
class SitemapController extends Controller
{
public function build()
{
$sitemapIndex = SitemapIndex::create();
$taxonomies = ['cases_categories', 'news_categories'];
foreach ($taxonomies as $taxonomy) {
$terms = Term::whereTaxonomy($taxonomy)
->where('sitemap', '!=', 'false')
->where('sitemap', '!=', 'Exclude');
$this->build_index($terms, "sitemaps/{$taxonomy}_sitemap.xml");
$sitemapIndex->add("/sitemaps/{$taxonomy}_sitemap.xml");
}
$sitemapIndex->writeToFile(public_path('/sitemaps/sitemap.xml'));
protected function build_index($entries, $path)
{
$sitemap = Sitemap::create();
foreach ($entries as $entry) {
$sitemap->add(
Url::create($entry->absoluteUrl())
->setPriority($entry->get('meta_priority', 0.5))
->setChangeFrequency($this->get_frequency($entry->get('change_frequency')))
->setLastModificationDate(Carbon::parse($entry->lastModified()))
);
}
$sitemap->writeToFile(public_path($path));
return $path;
}
protected function get_frequency($frequency)
{
return match ($frequency) {
'daily' => Url::CHANGE_FREQUENCY_DAILY,
'always' => Url::CHANGE_FREQUENCY_ALWAYS,
'hourly' => Url::CHANGE_FREQUENCY_HOURLY,
'weekly' => Url::CHANGE_FREQUENCY_WEEKLY,
'yearly' => Url::CHANGE_FREQUENCY_YEARLY,
'monthly' => Url::CHANGE_FREQUENCY_MONTHLY,
default => Url::CHANGE_FREQUENCY_MONTHLY,
};
}
}
Your manual setup looks solid. Consider using Statamic's built-in SEO fields or a global variable for default meta. Smart sitemap approach.
Please or to participate in this conversation.