Re: How to get "Meta Description" field in Product liquid object

How to get "Meta Description" field in Product liquid object

ellekaie
Tourist
8 1 4

Requirement:

On the search page, we want to change how the item description appears. We want the search results to show the contents of the Meta Description instead of the Description. In the Product page, Meta Description will only show if you click the Edit website SEO link below, at the Search engine listing preview section.

 

What I checked:

1. In our search liquid template, the items are printed under this loop:

 

 

{% for item in search.results %}

 

 

2. The item description is printed as such:

 

 

{{ item.content | strip_html | truncatewords: 30 }}

 

 

3. In product object in Shopify.dev, there is no direct reference to Meta Description field. I'm also aware of the metafield object also included in the product object but it is different since Meta Description is a standard field in Shopify products, we did not create that.

4. I know about the page_description object, but it is not applicable to the search liquid template. Unless there is a way to open the item as a page within the loop and get the page_description?

5. Found this thread in this forum, but the solution is not applicable on my end.

 

Any suggestions on how to implement our requirement? Thank you.

Replies 2 (2)

MetafieldsGuru
Shopify Partner
160 32 102

Hi @ellekaie ,

 

The thing is that a product's meta description is indeed stored as a metafield:

MetafieldsGuru_0-1658321132594.png

Here's the link to the docs from my screenshot.

 

You can check it with a pretty simple test:

1) Create a dummy product without the meta and default description;

2) Use the Shopify admin API to access the list of metafields and see that there's no "description_tag" metafield for this product. Add the following code:

/metafields.json?namespace=global&key=description_tag

to the product URL while in the admin panel. As a result, the URL in the address bar would look like this:

MetafieldsGuru_1-1658322007710.png

Press enter.

3) Go back to the product editing page and add a test seo description.

4) Use the API just like we did in the second step of this list.

 

Since the data is stored as a metafield, you can access and display it's content on the product page with the following Liquid code:

{{ product.metafields.global.description_tag.value }}
Check out Metafields Guru, the #1 ranked metafields app.

Bulk editor | Data import/export | Metafield sets | Browser extension
ellekaie
Tourist
8 1 4

Thank you so much! Will look into this.