Prevent WordPress posts from copying

Prevent WordPress posts from copying

I will share a code to prevent your wordpress posts from copying. Actual it will not stop copying, but it will show a custom message while pasted.

<script type="text/javascript">
function addLink() {
    var pageLink = "<BR/><BR/>Read more: " + document.location.href; // Get the current page link
    var copytext = "Copying Not Allowed" + pageLink + "<BR/><BR/>Join our Whatsapp group: https://chat.whatsapp.com/GroupName";

    var newdiv = document.createElement('div');

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

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

    window.setTimeout(function () {
        document.body.removeChild(newdiv);
    }, 100);
}

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

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 *