Create line break in WhatsApp message

ravi patel picture ravi patel · Jan 5, 2015 · Viewed 30.3k times · Source

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.

Answer

am2505 picture am2505 · Oct 12, 2019

If you want to send an only text containing newline

use this %0a


link =`whatsapp://send?text=%0a‎Hello%0aWorld`;

If you want to send some url link with text containing newline

var encodedURL = encodeURIComponent(some_url);
link =`whatsapp://send?text=${encodedURL}%0a‎Hello%0aWorld`;

Now embedded this link in anchor tag

<a href=link> Click here! </a>