I have been working on WhatsApp sharing message using:
whatsapp-button.js
$_u.="Product Name:".$_productName."\n";
$_u.="Sku:".$_productSku."\n";
<a href="whatsapp://send" data-text="<?php echo nl2br($_u); ?>" data-href="" class="wa_btn <?php echo $buttonsize; ?>" style="display:none">Share</a>
How to add a line break:
I have tried \n
, \r\n
, PHP_EOL
, and %0D%0A
, but it just displays as text.
If you want to send an only text containing newline
use this %0a
link =`whatsapp://send?text=%0aHello%0aWorld`;
If you want to send some url link with text containing newline
var encodedURL = encodeURIComponent(some_url);
link =`whatsapp://send?text=${encodedURL}%0aHello%0aWorld`;
Now embedded this link in anchor tag
<a href=link> Click here! </a>