Prevent Twitter from Converting @Mentions into Links
If your tweet contains two words that are separated by a dot (or period), Twitter may sometimes interpret that combination as a web address and will auto-convert the words into a clickable hyperlink wrapped inside a t.co URL.
Similarly, if you add the ”@” symbol before any word in a tweet, Twitter may see that as a mention and will automatically link that word to a Twitter profile. And words starting with the # hash sign are converted into links pointing to search results as well.
These auto-generated links are useful in most cases but sometimes you may just want twitter to display your tweets in plain text and not convert words into links. For instance, see this tweet:
It includes the same text (labnol.org) twice but in the first case, Twitter is pointing to a website and in the other case, it’s pointing to a Twitter profile.
If you would like to prevent Twitter from interpreting two consecutive words as a URL, just add a zero width space after the dot. Similarly, if you would not like Twitter to auto-convert @mentions or #tags into hyperlinks, add a zero width space after the @ or # symbol respectively.
The HTML code for zero width space is but you cannot add HTML codes directly inside Twitter so here’s a simple workaround.
<p> Enter text: <input id="tweet" onkeyup="document.getElementById ('result').innerHTML='<br />'+this.value.replace(/([@#\.])/ig, '$1​');" type="text" /> <span id="result" style="background:lightyellow"></span> </p>
Enter some text in the input box above and it will automatically add zero width space after every dot, #hash or @mention. You can then copy-paste the converted text into you Twitter and none of the words will ever get converted into hyperlinks.
Google Developer Expert, Google Cloud Champion
Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India.