Comments (5)
So first, a preamble... which is that retrofitting a plugin like SEOmatic to a project is always going to be a little less clean than if it was designed to use it from the get-go. It really is a different set of requirements for the plugin to be good at being retrofitted vs. being good at working out of the box in a new project.
That said, a few people have suggested the idea of "defaults" for the SEOmeta Meta FieldType. I'm onboard, and like the idea. Here's the problem. Fields in Craft are their own little islands; they can exist in a dozen or more EntryType layouts.
So the global settings that you can assign to a field exist outside of the context of any Field Layout. You can't (I know, I started to try) declare some settings that allow you pick one of the other fields in the Field Layout to pull from like you can do from within the Entry itself.
At best, what can be done is I display a popup menu of all sections, and than all Field Layouts where the field exists, the user picks one, and then they pick the field to pull from. It's a little gross, and the other problem with this approach is because the settings are global, if that SEOmatic Meta field is included in two Field Layouts, then it's going to be defaulting them both to the same thing. Which I think probably is never good.
That's why I stopped at implementing this; I'm trying to figure out a better way to do it, but failing.
from seomatic.
As a solution for now, you can do what you want by using Twig to set your meta, something like this:
{% set seomaticMeta = {
seoTitle: entry.title,
seoDescription: entry.summary,
seoKeywords: extractKeywords(entry.body),
seoImage: seomaticMeta.seoImage,
canonicalUrl: entry.url,
twitter: {
card: seomaticMeta.twitter.card,
site: seomaticMeta.twitter.site,
creator: seomaticMeta.twitter.creator,
title: entry.title,
description: entry.summary,
image: seomaticMeta.twitter.image
},
og: {
type: seomaticMeta.og.type,
locale: seomaticMeta.og.locale,
url: entry.url,
title: entry.title,
description: entry.summary,
image: seomaticMeta.og.image,
site_name: seomaticMeta.og.site_name,
see_also: seomaticMeta.og.see_also
}
} %}
Put that in your blog template that extends
your layout.twig
(or whatever) that has the {% hook 'seomaticRender' %}
in it, and it'll "just work", override all of your other meta.
I realize it's not ideal, but it's the easiest way to handle it on a site where you're retrofitting SEOmatic, as opposed to integrating it from the start.
from seomatic.
Ok, thanks for explaining the problem – and for the implementation tip. I really appreciate it 👍
from seomatic.
Hm :)
{% set seomaticMeta = seomaticMeta | merge({
twitter: {
image: previewImages[2].url
}
}) %}
This works outside the {% block foo %}
but when I set it within this block it doesn't work.
Any Ideas?
from seomatic.
@davidhellmann Yes, you'll need to do that outside of the {% block %}
statements due to the way that Twig's processing order works:
https://straightupcraft.com/articles/twig-processing-order
Otherwise, you'll be setting the SEOmatic variables after the meta tags have already been rendered (so it won't do anything, effectively).
Also, you'll need do do the full array otherwise the other fields will get blown away, due to the way the Twig (poorly, imo) handles setting of arrays:
{% set seomaticMeta = seomaticMeta | merge({
twitter: {
card: seomaticMeta.twitter.card,
site: seomaticMeta.twitter.site,
creator: seomaticMeta.twitter.creator,
title: entry.title,
description: entry.summary,
image: previewImages[2].url
}
}) %}
from seomatic.
Related Issues (20)
- Sitemaps issue with multisite
- Enabling robots in devMode/local
- Overriding seomatic.meta.robots value has no effect on <meta> tag (in production environment) HOT 1
- Referrer-Policy should be updated
- Trying to get property 'sourceName' of non-object when clicking breadcrumb in seo content HOT 3
- Turn off x-powered-by: SEOmatic
- turn off Automatic Render Enabled and manually render scripts HOT 1
- Google Analytics showing /actions/seomatic URLs for some reason
- “Internal server error” when piggybacking (in PHP) HOT 2
- Google Tag Manager code ends up in body instead of head HOT 1
- Environment Variables/Aliases not parsed for humans.txt, though proposed in Text Field HOT 1
- Provide data in a structured way on GraphQL endpoint HOT 2
- Can't retrieve (GQL) or save (control panel) humans template HOT 1
- Section Entries Not Populating to Content SEO and Sitemap.xml HOT 2
- Pagination for Sitemaps / Sitemap Indexes HOT 2
- Sitemap Page loads slowly HOT 1
- Seo images don't update mtime when asset settings are changed. HOT 3
- SEO Image Source > render output with overlay image, logo or watermark HOT 5
- Algolia search on docs website is returning 404s HOT 4
- Unknown property error when upgrading to Craft 4 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from seomatic.