Magento 2 Rich Text Schema Setup in JSON-LD: Step-by-Step Guide
ecommerce Magento Technical

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!

Note: These issues persist in the default Magento setups till version 2.4.7, so if you are using any 3rd party theme or SEO extension, or any newer version in future, then this solution might not work for you. If you are facing any troubles following the guide or fixing the schema, feel free to reach out to us.

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:

Click here to view and edit & add your code between the textarea tags

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

Click here to view and edit & add your code between the textarea tags

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.

Click here to view and edit & add your code between the textarea tags

Creating templates Organization

Template File for organization schema

File

app/code/Azguards/RichTextSchema/view/frontend/templates/organizationschema.phtml
Click here to view and edit & add your code between the textarea tags

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.

Click here to view and edit & add your code between the textarea tags

Creating templates Products

Template File for Product schema

File

app/code/Azguards/RichTextSchema/view/frontend/templates/productschema.phtml
Click here to view and edit & add your code between the textarea tags

Product Schema Block

File

app/code/Azguards/RichTextSchema/Block/ProductSchema.php
Click here to view and edit & add your code between the textarea tags

Final Step: Deploy and Test Your Changes

After implementing the custom module, deploy the changes to your Magento store by running the following commands:

Click here to view and edit & add your code between the textarea tags

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.

need assisting with Magento 2 customization?