• Resolved ExOmRa

    (@exomra)


    Hi, does it possible to add new fields (like brand, review and other) for Schema Output? I use code in function.php to take data from product attribute.

    add_filter( 'the_seo_framework_generated_description', function( $description, $args ) {
    	if ( null === $args && is_product() ) {
    		global $product;
    		$brand = $product->get_attribute( 'brand' );
    	}
    	return $brand;
    }, 10, 2 );
    

    But I don’t know how to write the right filter

    • This topic was modified 5 years, 1 month ago by ExOmRa.
    • This topic was modified 5 years, 1 month ago by ExOmRa.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Sybre Waaijer

    (@cybr)

    Hello!

    You can modify and expand the Schema.org output via this filter:
    the_seo_framework_receive_json_data

    The first parameter is the JSON data, and the second parameter is the key/type (WebSite, Links, Breadcrumbs_0, etc.)

    Via Google’s Structured Data testing tool you can test your modifications: https://search.google.com/structured-data/testing-tool/.

    Please note that we’re going to reimplement that filter differently in the upcoming major update.

    Also, note that we disable the BreadcrumbList script for WooCommerce products, and let WooCommerce output the data instead.

    I hope this gets you off to a good start! Cheers ??

    Thread Starter ExOmRa

    (@exomra)

    Thanks for the answer, but seems this filter doesn’t work for page with products. Or I just dont know how to write it right. I use this construction:

    add_filter( 'the_seo_framework_receive_json_data', function( $data, $key ) {
    	switch ( $key ) :
    		case 'product':
    			$data['brand'][] = 'test';
    			break;
    
    		default:
    			// Unknown key... don't do anything.
    			break;
    	endswitch;
    
    	return $data;
    }, 10, 2 );
    Plugin Author Sybre Waaijer

    (@cybr)

    Hi again!

    TSF doesn’t output Schema.org product markup; so, that’s why that filter won’t work.

    To reiterate: On WooCommerce product pages, The SEO Framework’s schema markup is disabled. Instead, we let WooCommerce output the Schema.org markup.

    If you look in the HTML source code, do you see the markup being outputted by TSF, or by another plugin, like WooCommerce? If it’s WooCommerce, then you should look into their documentation on this.

    e.g.

    add_filter( 'woocommerce_structured_data_product', function( $markup, $product ) {
        $markup['sku'] = $product->get_id(); // Set sku to product id.
        return $markup;
    } );
    Thread Starter ExOmRa

    (@exomra)

    Thanks for your help. This is the solution code. Hope it will help someone.

    add_filter( 'woocommerce_structured_data_product', function( $markup, $product ) {
    	if( is_product() ) {
    		$markup['brand'] = $product->get_attribute( 'brand' );
    		$markup['mpn'] = $product->get_attribute( 'mpn' );
    	}
    	return $markup;
    }, 10, 2 );
    • This reply was modified 5 years, 1 month ago by ExOmRa.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add new fields for Schema Output’ is closed to new replies.