Making meta implementation for your Craft CMS sites slightly less painless.
SimpleMeta provides you with the following tools:
- SimpleMeta fieldtype.
- Front-end template tag for outputting meta data.
- Copy the
simplemeta
directory into your site's plugins directory, usuallycraft/plugins
. - Install the plugin in your site's control panel.
Create a new SimpleMeta
field and include it any any field layout you would like. We recommend creating a new tab called "Meta" (or whatever you prefer) and including the SimpleMeta
field there. There are quite a few options. The meta data is then stored with the entry.
There are two ways to output the meta in your template:
Use the output
method included. This outputs all meta in one handy-dandy tag, with a little bit of work from you the developer.
{{ craft.simpleMeta.output(entry, fallback)|raw }}
This requires one parameter, entry
, with an optional second fallback
parameter. The entry
parameter should be the current page entry. The fallback
parameter would be used in cases where there isn't an entry. We recommend creating a global with an instance of the SimpleMeta
field for your fallback. This essentially provides default meta data for those cases where an entry isn't available. You also then have the ability to create more than fallback if you need to. We leave this implementation up to you.
This example assumes that you have a global entry with a handle of metaFallback
with an instance of the SimpleMeta
fieldtype.
{% set entry = entry is defined ? entry %}
{% set fallback = craft.globals.getSetByHandle('metaFallback') %}
{{ craft.simpleMeta.output(entry, fallback)|raw }}
The fallback will work as both a fallback if the entry doesn't exist, but will also act as a default to fill in values not present in the entry. So, for example, if you have a description
in your fallback, but not in the entry, the description
from the fallback will be output.
The output
tag will no longer include the <title>
tag. This will need to be implemented by you. Example forthcoming on how you can handle this.
You can access any of the SimpleMeta
fields directy via the entry if you prefer to setup your own custom output.
Note: For fields that return an Asset ID you can use Craft's craft.assets
. Check out the example below:
{% set socialOGImageId = craft.assets.id(entry.fieldHandle.socialOGImageId).first() %}
{{ socialOGImageId.url() }}
?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{% set entries = craft.entries.section(['blog', 'pages', 'team',]) %}
{% for entry in entries %}
<url>
<loc>{% if entry.fieldHandle.seoCanonicalUrl is not empty %}{{ entry.fieldHandle.seoCanonicalUrl }}{% else %}{{ entry.url }}{% endif %}</loc>
<lastmod>{{ entry.dateUpdated }}</lastmod>
<changefreq>{{ entry.fieldHandle.seoSitemapChangeFrequency }}</changefreq>
<priority>{{entry.fieldHandle.seoSitemapPriority}}</priority>
</url>
{% endfor %}
</urlset>
Property | Tag | Returns |
---|---|---|
Title | {{ entry.fieldHandle.socialOGTitle }} |
String |
Description | {{ entry.fieldHandle.socialOGDescription }} |
String |
Image | {{ entry.fieldHandle.socialOGImageId }} |
Asset ID |
Type | {{ entry.fieldHandle.socialOGType }} |
String |
Property | Tag | Returns |
---|---|---|
Include Video | {{ entry.fieldHandle.socialOGVideoInclude }} |
String |
Video | {{ entry.fieldHandle.socialOGVideoEmbeddedUrl }} |
String |
https://dev.twitter.com/docs/cards
Property | Tag | Returns |
---|---|---|
Title | {{ entry.fieldHandle.socialTwitterTitle }} |
String |
Description | {{ entry.fieldHandle.socialTwitterDescription }} |
String |
Type | {{ entry.fieldHandle.socialTwitterType }} |
String |
Property | Tag | Returns |
---|---|---|
Image | {{ entry.fieldHandle.socialTwitterSummaryImageId }} |
Asset ID |
Property | Tag | Returns |
---|---|---|
Image | {{ entry.fieldHandle.socialTwitterSummaryLargeImageId }} |
Asset ID |
Property | Tag | Returns |
---|---|---|
Image | {{ entry.fieldHandle.socialTwitterPhotoId }} |
Asset ID |
Property | Tag | Returns |
---|---|---|
App Name iPhone | {{ entry.fieldHandle.socialTwitterAppIphoneName }} |
String |
App ID iPhone | {{ entry.fieldHandle.socialTwitterAppIphoneId }} |
String |
App URL iPhone | {{ entry.fieldHandle.socialTwitterAppIphoneUrl }} |
String |
App Name iPad | {{ entry.fieldHandle.socialTwitterAppIpadName }} |
String |
App ID iPad | {{ entry.fieldHandle.socialTwitterAppIpadId }} |
String |
App URL iPad | {{ entry.fieldHandle.socialTwitterAppIpadUrl }} |
String |
App ID Google Play | {{ entry.fieldHandle.socialTwitterAppAndroidName }} |
String |
App Name Google Play | {{ entry.fieldHandle.socialTwitterAppAndroidId }} |
String |
App URL Google Play | {{ entry.fieldHandle.socialTwitterAppAndroidUrl }} |
String |
App Country | {{ entry.fieldHandle.socialTwitterAppCountry }} |
String |
Property | Tag | Returns |
---|---|---|
Image | {{ entry.fieldHandle.socialTwitterProductImageId }} |
Asset ID |
Label 1 | {{ entry.fieldHandle.socialTwitterProductLabel1 }} |
String |
Data 1 | {{ entry.fieldHandle.socialTwitterProductData1 }} |
String |
Label 2 | {{ entry.fieldHandle.socialTwitterProductLabel2 }} |
String |
Data 2 | {{ entry.fieldHandle.socialTwitterProductData2 }}} |
String |
Property | Tag | Returns |
---|---|---|
Title | {{ entry.fieldHandle.seoTitle }} |
String |
Description | {{ entry.fieldHandle.seoDescription }} |
String |
Canonical URL | {{ entry.fieldHandle.seoCanonicalUrl }} |
String |
Robots Index | {{ entry.fieldHandle.seoRobotsIndex }} |
String |
Robots Follow | {{ entry.fieldHandle.seoRobotsFollow }} |
String |
Sitemap Priority | {{ entry.fieldHandle.seoSitemapPriority }} |
String |
Change Frequency | {{ entry.fieldHandle.seoSitemapChangeFrequency }} |
String |