Getting metafields title tag and description tag through API

Ryan92
Tourist
12 0 1

Hi,

I've been trying to fetch the seo meta title tag and description from a product to use it with my app. In documentation under product it says there is an attribute  metafields_global_title_tag and metafields_global_description_tag but it doesn't fetch anything. Any ideas?

 

Replies 6 (6)
Jason
Shopify Expert
10882 190 2178

Where did you see the format for those metafields shown as "metafields_global_title_tag". The correct reference  should appear like so :

metafields.global.title_tag

 

  • namespace: global
  • key: title_tag or description_tag

If a product has not been given a custom SEO title or SEO descripton those metafields won't exist.

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★
Ryan92
Tourist
12 0 1

I saw it in the API reference under the product in the product properties table

Ryan92
Tourist
12 0 1

I found the answer, now the seem to appear on the endpoint admin/products/{ product_id }/metafields.json

Manuel5
New Member
1 0 0

Ryan is right, thanks.

The doc is outdated https://help.shopify.com/api/reference/product

The keys `metafields_global_title_tag` and `metafields_global_description_tag` don't exist.

dobeerman
New Member
1 0 0

Did anybody solve this issue with no keys?

Kevin_Williams
Excursionist
34 0 8

Try this:

{{ product.metafields.global.description_tag | default: product.description | strip_html | truncatewords: 150, '' }}

Truncation is optional and included if product description fallback is necessary.