Last active
March 23, 2017 18:59
-
-
Save MrJSdev/f98e59a492a816801aa54842ee793c13 to your computer and use it in GitHub Desktop.
Read More link when someone copy your article
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Do Not copy open php tag */ | |
/** | |
* @author Hunk Riyaz | |
* @link http://extracatchy.net | |
*/ | |
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 ExtraCatchy: <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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
going to make tutorials of this code at my website http://extracatchy.net