In this video I want to demonstrate how you can overwrite properties from global snippets.
Transcript
Hey and welcome back. Nice to have you in the third lesson of module 2.
I’m Florian, the developer of SNIP, the Rich Snippets and Structured Data Plugin for WordPress. If you want to use the plugin, please feel free to follow the link that you can find in the description area.
Example: A Global Recipe Snippet
Now let’s say I’m working on a website that offers recipes.
I know from the previous videos that Google (and maybe other search engines) show a Rich Snippet in search results if I use structured data for Recipes.
If done right, the snippet shows a picture of my dish, a star rating, servings, the total cooking time, the calories and so forth.
Because you don’t want to create a single recipe snippet for each recipe-page, you’ve decided that you create a Global Snippet.
If you don’t know yet what Global Snippets are, please go back one video where I explain in every detail why this functionality saves you a ton of work.
Let’s have a look at Global Snippets in the plugin again.
Global Snippets
When logged-in to your WordPress dashboard click the „Global Snippets“ link from the menu. That will bring you to the overview of all Global Snippets.
We now click on the Recipe. A Recipe is a very good example that explains how overwriting of Global Snippet properties works and why it makes sense to use this functionality.
SNIP – My Rich Snippets and Structured Data WordPress Plugin ships with a Global Recipe Snippet already. So in most cases you’re ready to go. However we’ll have a closer look to it now anyway. So that you understand how everything works.
When you move your mouse over a property row you can see that there are two checkboxes. One that says „overridable“ and one that says „List“. I will explain the two in every detail but for now I’ll show you how overriding works.
Before we start you need to know the following…
Prerequisites
I’ve a custom post type named „recipes“. For now I have only one recipe published.
On the settings page of SNIP I selected „Recipes“ on the select box so that I can use snippets there as well.
Because I think everyone likes to eat donuts, I wrote about donuts in my first recipe-post. So let’s take a closer look at this post.
As you can see a typical recipe post has some information like:
- the image;
- Information about yield and the cooking time;
- A list of ingredients;
- Preparation steps and so on.
We want to integrate this information into our global snippet.
How to work with overridable properties
As you have seen in one of the previous screenshots, some of the properties of the Global Recipe snippets are marked as overridable.
When you edit the fields you also see that the field type for „Yield“ is „Direct text input“, but the field value is empty. This is because it’s overwritten on each post separately so you don’t need a value here.
In some special cases you maybe want to add a default value. If that is the case you can enter some text here.
The prepTime
and cookTime
properties are also marked overridable. As you can see, the field type is a duration with a default value of 30 minutes. The duration is a special field type because schema.org forces us to use a special time format for durations.
To be exact, the time format should be in the format how ISO 8601 defines it. In this format a value of 30 minutes would look like this this: PT30M
. That’s weird because no one knows exactly how to use that time format. So I wrote a little wrapper function that allows you to just add minutes. The wrapper function will then translate this into the special format that search engines need.
Let’s go back to our recipe post. As you can see, there is a new button in the sidebar that is labeled „Edit global snippets“. A click on it opens up a popup window.
On the left side you can see all the global snippets that are available. We click on the recipe.
Now, all the fields, that are marked overridable, are listed. We can see the recipeYield`
When you scroll down you can see that prepTime
, the cookTime
as well as the totalTime
. They’re all marked overridable and the field type is a duration. That allows a user to enter the duration in minutes.
But there are even more values that are overridable. Like the review, the description and so on. Just go back to the Global Snippet to check what properties I have marked overridable and you will recognize how easy it is to work with this fantastic tool.
To sum it up shortly: you should mark a property overridable if it needs to be different in every post and if you expect an explicit user input.
If some data is already there, for example if you use a plugin that lets you gather recipe data directly via a special form, you should try to use this data instead. Here is an example:
If you set up the popular Advanced Custom Fields plugin to allow for entering recipe data, you can use this data instead. I’ve explained how this works in the previous video about Global Snippets and how you can use post meta data.
Now let’s go back to our global recipe snippet again.
How to work with “list” properties
Earlier in this video I told you that there is another checkbox that is labeled „List“.
This checkbox should always be selected if the property can have multiple values. In our Recipe Snippet that would be the case for the recipeIngredient
property. That makes sense because a recipe always has multiple ingredients.
- Let’s go back to our recipe again.
- Click the „Edit global snippets“ button again.
- Choose „Recipe“ from the left menu and wait until all the properties are loaded.
Now you can see that after the recipeIngredient
there are two symbols. A plus-sign that adds a new input field and a trash-icon to allow deleting the property. Let’s click on the plus-sign a few times.
You see that we now have multiple recipeIngredient
properties. You can start to enter your ingredients now.
Note that all properties, that have been marked with the List-Checkbox, are merged together to a single property later. So Googles Structured Data Test Tool will only see one property but this property will have multiple values
Don’t be frightened when I show you the sourcecode now. But you should be familiar with it already. I’ve shown it to you in the very first videos of this Structured Data Training.
{
"@context": "http:\/\/schema.org",
"@type": "Recipe",
"name": "Recipe for Donuts",
"aggregateRating": {
"ratingCount": "1",
"bestRating": "5",
"worstRating": "0",
"@context": "http:\/\/schema.org",
"@type": "AggregateRating"
},
"recipeIngredient": [
"1¼ cups milk",
"2¼ teaspoons (one package) active dry yeast",
"2 eggs"
],
...
}
As you can see, there is only one recipeIngredient
property that inherits all ingredient texts one by one.
We as developers say that the property is now an array of items.
So to sum this up: the list checkbox should be used when you want to create an array of elements. In other words: if you want to merge multiple properties of the same name together.
Summary
That’s it! It’s time to sum everything up.
- In this video you have learned that it’s possible to overwrite certain properties of global snippets one by one if they’re marked overridable.
- You can use this feature whenever you need an explicit user input. In other words: if you need a value that is different within every post and cannot be gathered automatically.You can also choose from a variety of field types that makes it easier to add certain data like a duration-value shown in this video.
- You have learnt that you can mark certain properties as lists.
- That allows you to create an array of values. That is particular useful for properties like the ingredient property shown in this video.
- Last but not least, if global snippet values are marked overridable you can fill them in the „Global snippets window“ that you can reach from your posts, pages or custom post types.
Wow! You’ve now reached the end of module 2! Congratulations! You’ve learned everything from the ground up: What Structured Data is, what Rich Snippets are, why they’re useful and you now know how SNIP – The Rich Snippets and Structured Data WordPress plugin works altogether.
In module 3 I’ll go through every Schema that is currently supported by Google and produces a Rich Snippet in search results. Feel free to pick one that you need.
See you there!