Last active
April 28, 2023 08:37
-
-
Save mattiasghodsian/c054a3f6af592d2c07c5379577f0d6a5 to your computer and use it in GitHub Desktop.
Add YITH Brand to Schema on Product page
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
| /** | |
| * Title: Add YITH Brand to Schema on Product page | |
| * Author: Mattias Ghodsian | |
| * Description: This is for yith-woocommerce-brands-add-on-premium plugin | |
| * Donate a cup of coffee: https://www.buymeacoffee.com/mattiasghodsian | |
| * Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5 | |
| **/ | |
| function yith_brand_schema() { | |
| if ( is_product() ) { | |
| $brand = get_the_terms( get_the_ID() , 'yith_product_brand' ); | |
| if ( !is_wp_error($brand) ) { | |
| if ( isset($brand[0]) ) { | |
| $brand = $brand[0]; | |
| $thumbnail_id = get_woocommerce_term_meta( $brand->term_id, 'thumbnail_id', true ); | |
| $brand_image = wp_get_attachment_url( $thumbnail_id ); | |
| ?> | |
| <script type="application/ld+json"> | |
| { | |
| "@context": "http://schema.org", | |
| "@type": "Brand", | |
| "name": "<?php echo $brand->name; ?>", | |
| "url": "<?php echo get_term_link($brand); ?>", | |
| "logo" : "<?php echo $brand_image; ?>", | |
| "description" : "<?php echo strip_tags($brand->description); ?>" | |
| } | |
| </script> | |
| <?php | |
| } | |
| } | |
| } | |
| } | |
| add_action( 'wp_head', 'yith_brand_schema' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment