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

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 %}
  1. The item description is printed as such:
{{ item.content | strip_html | truncatewords: 30 }}
  1. 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.

  2. 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?

  3. 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.

Hi @ellekaie ,

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

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.

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

  2. 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 }}
5 Likes

Thank you so much! Will look into this.