Last active
July 3, 2025 15:43
-
-
Save damiencarbery/d13b21b4407bd699e8e13bd1d445f4ef to your computer and use it in GitHub Desktop.
Google Structured Data for WooCommerce: Keep Google happy by providing product info in a form it can easily read https://www.damiencarbery.com/2019/04/google-structured-data-for-woocommerce/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Google Structured Data for WooCommerce | |
Plugin URI: https://www.damiencarbery.com/2019/04/google-structured-data-for-woocommerce/ | |
Description: Add Google Structured Data to WooCommerce products. Asked in: https://www.facebook.com/groups/genesiswp/permalink/2358845040833346/ | |
Author: Damien Carbery | |
Version: 0.1 | |
*/ | |
add_action( 'woocommerce_before_single_product_summary', 'dcwd_add_wc_structured_data' ); | |
function dcwd_add_wc_structured_data() { | |
$product = wc_get_product( get_the_ID() ); | |
?> | |
<!-- JSON-LD markup generated by Google Structured Data Markup Helper. --> | |
<script type="application/ld+json"> | |
{ | |
"@context" : "http://schema.org", | |
"@type" : "Product", | |
"name" : "<?php echo $product->get_name(); ?>", | |
"image" : "<?php echo get_the_post_thumbnail_url( $product->get_id(), 'full' ); ?>", | |
"description" : "<?php echo $product->get_short_description(); ?>", | |
"brand" : { | |
"@type" : "Brand", | |
"name" : "<?php echo $product->get_name(); ?>" | |
}, | |
"offers" : { | |
"@type" : "Offer", | |
"price" : "<?php echo $product->get_price(); ?>" | |
} | |
} | |
</script> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment