For social media sharing I am trying to get the first image URL which is greater than 200px using jQuery. This is my code which is not working:
$("body img").each(function() {
var $minHeight = 200;
if ($(this).height() > $minHeight) {
$(this).attr('src')
}
});
After getting the right image I need to change the default image URL in content="default-image.png" below:
<meta property="og:image" name="twitter:image" content="default-image.png"/>
This is a working selector for meta tag I found:
$('meta[property=og\:image]').attr('content','new-image.png');
I Found My Code Is Working But...
$("body img").each(function() {
var $minHeight = 200;
if ($(this).height() < $minHeight) {
$x = $(this).attr('src')
}
});
$('meta[property=og\:image]').attr('content',$x);
$(".share a[href*='pinterest']").prop("href","https://pinterest.com/pin/create/button/?url=http://mywebsite.com/mypage&media="+$x);
But above script is not working with greater than sign as needed if ($(this).height() > $minHeight)
Aucun commentaire:
Enregistrer un commentaire