DEV Community

Cover image for Share intention on Twitter, Facebook websites & WhatsApp app
Luke
Luke

Posted on

Share intention on Twitter, Facebook websites & WhatsApp app

If You want to click on a link and share some custom text, url or hashtags on social networks websites then use the following examples on any href property of <a>

Share intention Twitter

<a href={`https://twitter.com/intent/tweet?text=${encodeURIComponent(TEXT)}&url=${encodeURIComponent(URL)}&hashtags=tag1,tag2}`}>Share on Twitter</a>
Enter fullscreen mode Exit fullscreen mode

Share intention Facebook

<a href={`https://www.facebook.com/sharer.php?u=${encodeURIComponent(URL)}&quote=${encodeURIComponent(TEXT)}`}>Share on Facebook</a>
Enter fullscreen mode Exit fullscreen mode

Share intention WhatsApp (mobile only)

<a href={`https://wa.me/?text=${encodeURIComponent(TEXT)}%20${encodeURIComponent(URL)}`}>Share on WhatsApp</a>
Enter fullscreen mode Exit fullscreen mode

CodeSandbox available 🙂

📚 Read my other articles

English
Spanish

Top comments (0)