Skip to main content

Optimize storefront SEO

You can change the way a product, page, collection, blog, or article appears in search engine results by updating the resource's meta tags. The meta tags are the page title and the meta description, which are part of the resource's search engine listing.

For example, when you create a product, the page title and meta description for the product page defaults to the product title and description.

This guide shows you how to change these default values by managing metafields with the GraphQL Admin API.



Anchor to Step 1: Update a resource's search engine listingStep 1: Update a resource's search engine listing

If the resource's search engine listing has never been updated, then you can update the page title and meta description by creating the title_tag and description_tag metafields. If the resource's search engine listing has already been updated, then you can update the title_tag and description_tag metafields by specifying the ID of the metafield you want to update.

After you've updated the page title and meta description, the values are stored in the title_tag and description_tag metafields. These metafields are both in the global namepsace have the single_line_text_field type.

The following example changes the title for a product's search engine listing:

POST https://{shop}.myshopify.com/api/{api_version}/graphql.json

GraphQL mutation

mutation {
productUpdate(
input: {
id: "gid://shopify/Product/5591484858390"
metafields: [
{
namespace: "global",
key: "title_tag",
value: "Matte black sunglasses",
type: "single_line_text_field"
}
]
}
) {
product {
metafields(first: 10) {
edges {
node {
key
value
}
}
}
}
}
}

JSON response

{
"data": {
"productUpdate": {
"product": {
"metafields": {
"edges": [
{
"node": {
"key": "title_tag",
"value": "Matte black sunglasses"
}
}
]
}
}
}
}
}

If the metafield already exists because it was created through the API or because the search listing was updated in the Shopify admin, then you need to supply the metafield ID to update the metafield:

POST https://{shop}.myshopify.com/api/{api_version}/graphql.json

GraphQL mutation

mutation {
productUpdate(
input: {
id: "gid://shopify/Product/5591484858390"
metafields: [
{
id: "gid://shopify/Metafield/21111411048611",
value: "Matte black sunglasses"
}
]
}
) {
product {
metafields(first: 10) {
edges {
node {
key
value
}
}
}
}
}
}

JSON response

{
"data": {
"productUpdate": {
"product": {
"metafields": {
"edges": [
{
"node": {
"key": "title_tag",
"value": "Matte black sunglasses"
}
}
]
}
}
}
}
}

Anchor to Step 2: Hide a resource from search engines and sitemapsStep 2: Hide a resource from search engines and sitemaps

If you want to hide a resource from search engines and sitemaps, then you can use a metafield to automatically add noindex and nofollow meta tags to the resource's pages. To add noindex and nofollow meta tags to a resource's pages, create a new metafield for the resource with the following attributes:

"namespace": "seo",
"key": "hidden",
"value": 1,
"type": "number_integer"
Note

If you hide resources from the sitemap, then they won't appear in search results when customers use storefront search. If you delete the metafield using the GraphQL Admin, then the noindex and nofollow meta tags are removed.

The following example hides a product from search engines and sitemaps:

POST https://{shop}.myshopify.com/api/{api_version}/graphql.json

GraphQL mutation

mutation {
productUpdate(
input: {
id: "gid://shopify/Product/5591484858390"
metafields: [
{
namespace: "seo",
key: "hidden",
value: "1",
type: "number_integer",
}
]
}
) {
product {
metafields(first: 10) {
edges {
node {
key
value
}
}
}
}
}
}

JSON response

{
"data": {
"productUpdate": {
"product": {
"metafields": {
"edges": [
{
"node": {
"key": "hidden",
"value": "1"
}
}
]
}
}
}
}
}


Was this page helpful?