Created
August 19, 2020 11:12
-
-
Save vivirenremoto/e77d7ccb0f70c7b8b1d10fe73507f3fb to your computer and use it in GitHub Desktop.
product schema dynamic tag
This file contains 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
var product_images = []; | |
jQuery(function () { | |
for (var i = 0; i < 5; i++) { | |
if (jQuery('rs-sbg:eq(' + i + ')').length) { | |
product_images.push(jQuery('rs-sbg:eq(' + i + ')').attr('data-lazyload')); | |
} | |
} | |
if (product_images.length == 0) { | |
product_images.push(jQuery("meta[property='og:image']").attr('content')); | |
} | |
var product_price = jQuery('.descuento strong').html().replace('€', ''); | |
var product_currency = 'EUR'; | |
var product_json = { | |
"@context": "https://schema.org/", | |
"@type": "Product", | |
"name": jQuery('h1 strong').html(), | |
"image": product_images, | |
"description": jQuery('meta[name=description]').attr('content'), | |
"brand": { | |
"@type": "Brand", | |
"name": jQuery("meta[property='og:site_name']").attr('content') | |
}, | |
"offers": { | |
"@type": "Offer", | |
"url": jQuery("meta[property='og:url']").attr('content'), | |
"priceCurrency": product_currency, | |
"price": product_price | |
} | |
}; | |
var el = document.createElement('script'); | |
el.type = 'application/ld+json'; | |
el.text = JSON.stringify(product_json); | |
document.querySelector('head').appendChild(el); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment