WooCommerce Add brand and gtin to product schema markup in Yoast

0 votes

I want to add a brand and a gtin to my product markup in WooCommerce. At the moment the Yoast SEO plugin already adds a lot of markup. But it only has the option to add the brand with a product attribute. In my case, the brand is based on a custom field. Also, the gtin is in a different field and couldn't be used with Yoast.

I found a code snippet in their docs which allows to add custom data to the markup:

add_filter( 'wpseo_schema_webpage', 'example_change_webpage' );

/**

 * Changes @type of Webpage Schema data.

 *

 * @param array $data Schema.org Webpage data array.

 *

 * @return array Schema.org Webpage data array.

 */

function example_change_webpage( $data ) {

    if ( ! is_page( 'about' ) ) {

        return $data;

    }

    $data['@type'] = 'AboutPage';

    return $data;

}

But that's not for products and I couldn't see how I can change that.

I also found an example for the schema piece product:

{

      "@context": "https://schema.org",

      "@graph": [

          {

              "@type": "Product",

              "@id": "https://www.example.com/#/schema/product/abc123",

              "name": "Example Product",

              "image": {

                  "@id": "https://www.example.com/#/schema/image/abc123"

              }

          }

      ]

  }

I could use that in a custom function and add it as javascript in the head. Like this:

add_action( 'wp_head', function() {

    if ( is_product() ): 

    

    ?>

    

    <script type="application/ld+json">{

          "@context": "https://schema.org",

          "@graph": [

              {

                  "@type": "Product",

                  "@id": "#product",

                  "brand": {

                      "@id": "https://www.example.com/#/schema/organization/abc123"

                  },

                  "sku": "abc123",

              }

          ]

      }</script>

    

<?php

endif;

 }, 99 );

But now I have two different schema markups for the product.

Isn't there a way to add content to the existing markup from Yoast?

Mar 13, 2022 in Digital Marketing by Kichu
• 19,050 points
819 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Digital Marketing

0 votes
1 answer

How to remove home page title in Yoast SEO?

Here, you have two possibilities. You can ...READ MORE

answered Mar 4, 2022 in Digital Marketing by narikkadan
• 63,420 points
2,454 views
0 votes
0 answers

Can I remove the JSON-LD schema that Yoast adds to my WordPress site?

would like to remove the JSON-LD schema ...READ MORE

Mar 3, 2022 in Digital Marketing by Kichu
• 19,050 points
803 views
0 votes
0 answers

Text should be kept in ppt, pdf, or on html pages to get more SEO benefits and good results at SERP

best method/option for the text to be ...READ MORE

Mar 6, 2022 in Digital Marketing by Kichu
• 19,050 points
372 views
0 votes
0 answers

What is Keyword Density and how to create a script in PHP?

I am Working on a project to ...READ MORE

Mar 12, 2022 in Digital Marketing by Kichu
• 19,050 points
337 views
0 votes
1 answer

Yoast SEO: remove og:description and twitter:description

add_filter("wpseo_opengraph_desc", "remove_yoast_og"); add_filter("wpseo_twitter_description", "remove_yoast_og"); function remove_yoast_og($description) { ...READ MORE

answered Mar 1, 2022 in Digital Marketing by narikkadan
• 63,420 points
342 views
0 votes
1 answer

How to over-ride meta data in Wordpress, using Squirrly SEO

if (is_archive()){ add_filter('sq_title', 'filter_product_wpseo_metadesc'); function filter_product_wpseo_metadesc($wpseo_metadesc){ ...READ MORE

answered Mar 1, 2022 in Digital Marketing by narikkadan
• 63,420 points
670 views
0 votes
0 answers

SEO: Why "indexed pages" in Webmaster Tools and the command "site:" gives so much difference?

"Indexed URLs: 305,509"webmaser shows this when i ...READ MORE

Mar 2, 2022 in Digital Marketing by Kichu
• 19,050 points
312 views
0 votes
0 answers

Adding microdata or schema.org for breadcrumb SEO in Drupal 7

I'm currently a little confused about microdata ...READ MORE

Mar 4, 2022 in Digital Marketing by Kichu
• 19,050 points
632 views
0 votes
0 answers

Calling Yoast SEO title in widget not work

I just install Wordpress SEO plugin by ...READ MORE

Mar 4, 2022 in Digital Marketing by Kichu
• 19,050 points
302 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP