16

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 4

17

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.

4
  • Ok great, thanks. Surprised this hasn't been asked before.
    – Ryan
    Commented Oct 8, 2014 at 5:30
  • A variation of it has... from which I partially recycled this answer.
    – Lindsey D
    Commented Oct 8, 2014 at 5:34
  • 1
    How do you deal with channel "index" or "listing" page metas? Since we can't control de fields of those pages?
    – jlcharette
    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.
    – Lindsey D
    Commented Jun 1, 2015 at 5:01
34

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 %}
2
  • 1
    Thanks for the clear explanation, naboovalley! This is how I think most do it and I would do it as well.
    – Ryan
    Commented 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.
    – 4midori
    Commented Oct 2, 2019 at 21:34
14

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).

1
  • You're biased but to be fair it's a really good plugin so that's allowed. :)
    – foamcow
    Commented Jun 2, 2018 at 9:18
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.