Share on WhatsApp link can be generated programmatically. We can also append our data like text or other links with the share link. In this post, we gonna check out the different ways of generating Share on WhatsApp links.
WhatsApp Share Link with Text & Url
In this, we will be seeing how to create a share on WhatsApp link, in which we can add our text message and some URLs.
The example code is demonstrated in Javascript
const url = "https://example.com/invoice/104" const shareText = `whatsapp://send?text=*Order Bill:*%0a${url}`
In the above code, the variable shareText contains share on WhatsApp URL. Which can be used in the HTML tag and create a link. When the user clicks on the link, the WhatsApp app opens with the share data attached to it.
<a href={shareText} > Click to share on WhatsApp </a>
Method 2:
const url = "https://example.com/invoice/104" const shareText = `https://api.whatsapp.com/send?text=*Order Bill:*%0a${url}`
WhatsApp share to Specific Phone Number with Dynamic Text, links
Generate share on WhatsApp URL, which sends messages to a specific phone number. Along with that some dynamic text data or links can be attached.
const url = "https://example.com/invoice/104" const shareText = `https://api.whatsapp.com/send?phone=919846098460&text=*Order Bill:*%0a${url}`
Here in the above code, I am generating WhatsApp share link. Which sends a message to a specific person on WhatsApp with number 919846098460 (91 is the country code)
Method 2:
https://wa.me/whatsappphonenumber/?text=urlencodedtext
eg: https://wa.me/919846098460?text=How%20are%20you%20?
In the above examples, we have learned how to create a WhatsApp share link. This link will open the share text, link context in the WhatsApp mobile app and make the share easy. We also have seen how to create a WhatsApp link to a specific number.