Magento 2 Rich Text Schema Setup in JSON-LD: Step-by-Step Guide
In our previous blog, we discussed how Magento 2’s default schema markup doesn’t quite meet SEO needs straight out of the box. If your Magento 2 store relies on the default Magento template, it likely won’t qualify for showing up as a product card in Google search results. We provided a detailed guide on fixing the issues with the default Magento 2 schema, however there’s an even better approach: implementing schema using JSON-LD format. Unlike the Microdata format used by default in Magento 2, JSON-LD is more flexible and preferred for schema due to its ease of use and efficiency.
For those unfamiliar, schema markup plays a crucial role in making your eCommerce site more visible on search engines. By adding Rich Text Schema, search engines can better understand your content, which improves SEO and enables rich snippets (like product widgets) that give you more space in Google Search page and attract clicks and boost visibility.
How can you add Rich Text Schema Markup in JSON-LD to your Magento 2 store?
The first option is to get a 3rd party extension. There are plenty of options available, but make sure to do a basic research (check the demos) and then purchase it, most of the extensions struggle with Magento 2 Configurable products. We would recommend going for an SEO extension from reputed publishers like Amasty or Mageworks which along with schema fixes gives many more features for SEO as well.
However, if you prefer the more exciting DIY approach, you can add this schema yourself with some basic Magento and PHP knowledge. This guide will walk you through the steps for setting up Rich Text Schema for products and organization details, ensuring your Magento 2 store stands out with structured data designed for search engine success. Let’s dive in!
Directory Structure
To make the required changes without them being overwritten by future updates, we’ll create a custom module. Here’s the basic structure:
Layout XML Configuration
Organization Schema Layout
File:
app/code/Azguards/RichTextSchema/view/frontend/layout/cms_index_index.xml
This file configures the layout for the CMS Index page, referencing the OrganizationSchema block to include the organization schema data
product Schema layout
File:
app/code/Azguards/RichTextSchema/view/frontend/layout/default.xml
This file configures the layout for the default page, referencing the ProductSchema block to include the product schema data.
Creating templates Organization
Template File for organization schema
File
app/code/Azguards/RichTextSchema/view/frontend/templates/organizationschema.phtml
Organization Schema Block
File:
app/code/Azguards/RichTextSchema/Block/OrganizationSchema.php
This block class contains the logic to create and return the structured schema data as a JSON string.
Creating templates Products
Template File for Product schema
File
app/code/Azguards/RichTextSchema/view/frontend/templates/productschema.phtml
Product Schema Block
File
app/code/Azguards/RichTextSchema/Block/ProductSchema.php
Final Step: Deploy and Test Your Changes
After implementing the custom module, deploy the changes to your Magento store by running the following commands:
Once the deployment is complete, test your product schema markup using Google’s Rich Results Testing Tool. Enter the URL of a product page, test a simple and config product, and ensure everything is correctly recognized.
Would you like to share this article?
need assisting with Magento 2 customization?
All Categories
Latest Post
- Magento 2 Rich Text Schema Setup in JSON-LD: Step-by-Step Guide
- Fixing Magento 2 Product Schema Markup | Missing “image” field FIX
- How to Dispatch Custom Events in Magento 2
- Adding Filters in Magento Admin Grid | Column and Non-Column Component
- How to add custom styles (Colors and Fonts) to Magento Admin Grid