Last active
March 23, 2017 19:05
-
-
Save MrJSdev/26cae325f7b2befa837cee688bb67a62 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
<?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() { | |
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 ExtraCatchy: <?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> | |
<?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