How To Add a Read More Link to Copied Text in WordPress

How To Get a Link Back to Your WordPress Site from Copy & Pasted Text

Hello Friends, In this article Today I am Gonna Show You How To Add a Read More Link to Copied Texts in WordPress

  1. First of all, Go to Your WordPress Dashboard.
  2. Then Go to Apprenance > Theme Editor.
  3. and select Your Theme in Theme Editor
  4. Find function.php file and Click on it.
  5. Go to end of the function.php file and paste This Code…

Code:

function add_copyright_text() {
    if (is_single()) { ?>

<script type='text/javascript'>
function addLink() {
    var selection = window.getSelection();
    var htmlDiv = document.createElement("div");
    for (var i = 0; i < selection.rangeCount; ++i) {
        htmlDiv.appendChild(selection.getRangeAt(i).cloneContents());
    }
    var selectionHTML = htmlDiv.innerHTML;
    var pagelink = "<br/><br/>Read more at BM Tech: <a href='"+document.location.href+"'>"+document.location.href+"</a>";
    var copytext = selectionHTML + pagelink;
    
    var newdiv = document.createElement('div');
    newdiv.style.position = 'absolute';
    newdiv.style.left = '-99999px';
    
    document.body.appendChild(newdiv);
    newdiv.innerHTML = copytext;
    selection.selectAllChildren(newdiv);
    window.setTimeout(function () { document.body.removeChild(newdiv); }, 0);
}
document.oncopy = addLink
</script>

<?php
}
}
add_action( 'wp_head', 'add_copyright_text');

If you like This article then Give him a Feedback In Comments.

Follow me on Social Media Platform

and also share Knowledge With Your Friends…

Thanks and Read Our Other Articles:

LEAVE A REPLY

Please enter your comment!
Please enter your name here