A WhatsApp share preview with repeated Malayalam post title text and a red-highlighted link area, showing a script-style blog card.
WhatsApp share preview showing Malayalam post title text and a highlighted link section with code context.

How to disable dual title while sharing a post to whatsapp (SOLVED)

You might have noticed that the title of a post will be written twice while sharing the link to whatsapp.

To avoid this, I will share a script here.

Just copy the title of post after publishing and paste it in whatsapp. It will append the custom text and a link to whatsapp group.

<script type="text/javascript">
function addLink() {
    // Temporarily remove the document title to prevent it from being copied
    let originalTitle = document.title;
    document.title = "";

    var link = document.createElement("a");
    link.appendChild(document.createTextNode("Link"));
    link.href = 'https://chat.whatsapp.com/GroupName';
    link.onclick = 'loadScript';

    // Get the selected text and append the extra info
    var selection = window.getSelection(),
        pagelink = '<br /><br /> Read more : ' + document.location.href,
        copytext = selection + pagelink + ' <br /><br />   <br /><br />Join our Whatsapp group->> ' + link,
        newdiv = document.createElement('div');

    // Hide the newly created container
    newdiv.style.position = 'absolute';
    newdiv.style.left = '-99999px';

    // Insert the container, fill it with the extended text, and define the new selection
    newdiv.appendChild(link); 
    document.body.appendChild(newdiv);
    newdiv.innerHTML = copytext;
    newdiv.style.fontWeight = 'bold';
    selection.selectAllChildren(newdiv);

    window.setTimeout(function () {
        document.body.removeChild(newdiv);
        document.title = originalTitle; // Restore the original title after copying
    }, 100);
}

document.addEventListener('copy', addLink);
</script>

Publish a post. Copy the title of that post after opening it. Paste it in whatsapp. It will not show the repeated titles.

See also  How We Added a WhatsApp Chat Button to Our Website — And Why Every Wayanad Business Should Do the Same

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *