Created
September 1, 2016 17:41
-
-
Save anonymous/4d4f6c9308ae71aaeaa3c09a120bce1c to your computer and use it in GitHub Desktop.
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
<script type=’text/javascript’> | |
function addLink() { | |
if ( | |
window.getSelection().containsNode( | |
document.getElementsByClassName(‘entry-content’)[0], true)) { | |
var body_element = document.getElementsByTagName(‘body’)[0]; | |
var selection; | |
selection = window.getSelection(); | |
var oldselection = selection | |
var pagelink = “<br /><br /> Read more at WPBeginner: <?php the_title(); ?> <a href='<?php echo wp_get_shortlink(get_the_ID()); ?>’><?php echo wp_get_shortlink(get_the_ID()); ?></a>”; //Change this if you like | |
var copy_text = selection + pagelink; | |
var new_div = document.createElement(‘div’); | |
new_div.style.left=’-99999px’; | |
new_div.style.position=’absolute’; | |
body_element.appendChild(new_div ); | |
new_div.innerHTML = copy_text ; | |
selection.selectAllChildren(new_div ); | |
window.setTimeout(function() { | |
body_element.removeChild(new_div ); | |
},0); | |
} | |
} | |
document.oncopy = addLink; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment