Patch for image preview in WhatsApp
Guite opened this issue · comments
Axel Guckelsberger commented
WhatsApp does only show a preview image (taken from og:image
meta tag) if the shared text actually starts with the URL. Hence, I propose to swap url and title at https://github.com/heiseonline/shariff/blob/develop/src/js/services/whatsapp.js#L67
Currently I apply an ugly workaround to do it afterwards like this:
if ($('li.shariff-button.whatsapp a').length > 0) {
var shareStart = 'whatsapp://send?text=';
var waBtn = $('li.shariff-button.whatsapp a').first();
var linkParts = waBtn.attr('href').split('%20http');
waBtn.attr('href', shareStart + 'http' + linkParts[1] + '%20' + linkParts[0].replace(shareStart, ''));
}
As soon as this is included the image properly appears in WhatsApp.