og:type
-
Hi @rilwis
How do I change <meta property=”og:type” content=”article”> to <meta property=”og:type” content=”product“> in product pages and add this meta tags:- product:price:amount
- product:price:currency
- product:availability
-
Is it possible?
Thank you
-
Hi @alishahcheraghi ,
Currently it’s not possible yet. But I’m wondering where do you get these tags from? They’re not in Facebook list nor Open Graph protocol website.
These tags use for rich pins in pinterest:
https://help.pinterest.com/en/business/article/product-pins#section-14556I’ve just added filters for open graph tags and updated the docs with that. Can you please try it?
add_filter( 'slim_seo_open_graph_type', function( $value, $tag ) { if ( is_post( 123 ) ) { $value = 'product'; } }, 10, 2 );
to
add_filter( 'slim_seo_open_graph_type', function( $value, $tags ) { if ( is_product() ) { $value = 'product'; } return $value; }, 10, 2 );
and
add_action( 'wp_head', function() { if ( is_product() ) { global $post, $wp_query; $postID = $wp_query->post->ID; $product = wc_get_product( $postID ); echo '<meta property="product:brand" content="REBOORA" />'. "\n"; echo '<meta property="product:price:amount" content="' . $product->get_price() . '" />'. "\n"; echo '<meta property="product:price:currency" content="' .get_woocommerce_currency().'" />'. "\n"; echo '<meta property="product:condition" content="new">'. "\n"; echo '<meta property="product:retailer_item_id" content="' . $product->get_sku() . '"/>'. "\n"; { if ( $product->is_on_backorder() ) { echo '<meta property="og:availability" content="backorder" />' . "\n"; echo '<meta property="product:availability" content="available for order" />' . "\n"; return; } if ( $product->is_in_stock() ) { echo '<meta property="og:availability" content="instock" />' . "\n"; echo '<meta property="product:availability" content="in stock" />' . "\n"; return; } echo '<meta property="og:availability" content="out of stock" />' . "\n"; echo '<meta property="product:availability" content="out of stock" />' . "\n"; } } } );
Hi @alishahcheraghi,
Did you try with the latest commit on Github?
Hi @rilwis
I changed some of the code and it worked.add_filter( 'slim_seo_open_graph_type', function( $value, $tag ) { if ( is_post( 123 ) ) { $value = 'product'; } }, 10, 2 );
should be:
add_filter( 'slim_seo_open_graph_type', function( $value, $tags ) { if ( is_product() ) { $value = 'product'; } return $value; }, 10, 2 );
And I added:
add_action( 'wp_head', function() { if ( is_product() ) { global $post, $wp_query; $postID = $wp_query->post->ID; $product = wc_get_product( $postID ); echo '<meta property="product:brand" content="REBOORA" />'. "\n"; echo '<meta property="product:price:amount" content="' . $product->get_price() . '" />'. "\n"; echo '<meta property="product:price:currency" content="' .get_woocommerce_currency().'" />'. "\n"; echo '<meta property="product:condition" content="new">'. "\n"; echo '<meta property="product:retailer_item_id" content="' . $product->get_sku() . '"/>'. "\n"; { if ( $product->is_on_backorder() ) { echo '<meta property="og:availability" content="backorder" />' . "\n"; echo '<meta property="product:availability" content="available for order" />' . "\n"; return; } if ( $product->is_in_stock() ) { echo '<meta property="og:availability" content="instock" />' . "\n"; echo '<meta property="product:availability" content="in stock" />' . "\n"; return; } echo '<meta property="og:availability" content="out of stock" />' . "\n"; echo '<meta property="product:availability" content="out of stock" />' . "\n"; } } } );
Thanks a lot for your support
Opps, my bad! I forgot to add the return statement.
Glad that you have it resolved! Let me know if you need any further help.
PS: I’ll release a new version now.
- The topic ‘og:type’ is closed to new replies.