How do you guys handle SEO? Do you just make your own meta fields and add them in the template manually or am I missing something? I did notice there are some plugins being developed but there are sites in the wild now so it's been handled some how. Thanks!
4 Answers
You basically have two options...
In the world of plugins, check out the SEOmatic plugin or Sprout SEO plugin.
On Craft 2, SEOmatic is free, Sprout SEO is $99.
On Craft CMS 3, the SEOmatic plugin and Sprout SEO plugin are both available and $99.
If you'd rather not use a plugin, then you're on your own to create and implement whatever fields you think you'll need. Depending on how you're approaching SEO, it could be fields like "Keywords", "Description", etc... and/or fields for the Facebook OG tags, or whatever you want! At that point, implementing your SEO fields would be nearly identical to implementing any other fields in Craft.
-
-
A variation of it has... from which I partially recycled this answer. Commented Oct 8, 2014 at 5:34
-
1How do you deal with channel "index" or "listing" page metas? Since we can't control de fields of those pages? Commented Jun 1, 2015 at 0:36
-
@JCharette I'd recommend posting a new question. Feel free to link back to this one for reference if it helps. Commented Jun 1, 2015 at 5:01
Without having to use a separate Plugin this is a good basic practice on setting up basic SEO for your site.
First create three new fields called "seoTitle", "seoDescription" and "seoKeywords". Put these three fields in a Global group called "globalSeo".
In your layout template "layouts/_layout.html"
{% set seoTitle = globalSeo.seoTitle %}
{% set seoDescription = globalSeo.seoDescription %}
{% set seoKeywords = globalSeo.seoKeywords %}
<!DOCTYPE html>
<html>
<head>
<title>{% if title is defined %}{{ title }}{% else %}{{ seoTitle }}{% endif %}</title>
<meta name="description" content="{% if description is defined %}{{ description }}{% else %}{{ seoDescription }}{% endif %}"/>
<meta name="keywords" content="{{ seoKeywords }}"/>
{# You can then use the same fields for Facebook tags etc.. or create separate fields. #}
<meta property="og:title" content="{% if title is defined %}{{ title }}{% else %}{{ seoTitle }}{% endif %}"/>
<meta property="og:description" content="{% if description is defined %}{{ description }}{% else %}{{ seoDescription }}{% endif %}"/>
</head>
<body>
You can now per template override these standard variables with your own for that particular page and/or template.
For a template:
{% extends "layouts/_layout" %}
{% set title = "This is a my custom Page Title" %}
{% set description = "This is a my custom Page Description" %}
For a entry:
{% extends "layouts/_layout" %}
{% set title = entry.title %}
{% set description = entry.descriptionField %}
.. or if you want to user to have custom control over the entry SEO as well you can always add the same "seoTitle" fields to the entry's Channel/Structure/Single and do:
{% extends "layouts/_layout" %}
{% set title = entry.seoTitle %}
{% set description = entry.seoDescription %}
-
1Thanks for the clear explanation, naboovalley! This is how I think most do it and I would do it as well.– RyanCommented Oct 8, 2014 at 5:58
-
Well explained. This is just about exactly what I do, it has worked well. I set up a bunch of global defaults, including OG (open graph) stuff, and let the user override them on a per-entry basis if they want.– 4midoriCommented Oct 2, 2019 at 21:34
Completely biased answer, but check out my SEOmatic plugin. It's pretty comprehensive, and it's free. If you're running Craft CMS 3, the SEOmatic plugin is available for Craft CMS 3 as well (but is not free).
-
You're biased but to be fair it's a really good plugin so that's allowed. :)– foamcowCommented Jun 2, 2018 at 9:18
Heres article on my blog about setting up basic SEO functionality for Craft CMS:
http://craftsnippets.com/articles/basic-seo-functionality-for-craft-cms
It presents two options:
- Using pure Twig code for handling
<title>
metatag. - Setting up basic SEOmetatags using Seomate plugin