This handy bit of code will add a copy write notice to your text when people copy it from your website, this code is for wordpress but could be adapted to fit other platforms, to add this code to your wordpress website add the following code into your themes functions.php file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
function add_copyright_text() { ?>
<script type='text/javascript'>
function addLink() {
var body_element = document.getElementsByTagName('body')[0];
var selection;
selection = window.getSelection();
var pagelink = "<br /><br /> Read more at Alex-wells.co.uk: <?php if(is_single()){ the_title();}?> <a href='"+document.location.href+"'>"+document.location.href+"</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');
|
Example of the outcome when pasted into a word document:

Need help installing this script on your website? contact me for any website development queries
I have installed the code on this website, but am not sure if i will keep it. The code is handy for adding a copy write notice but it is not always suitable – on this site i post allot of website development code (the above for example) and the script will add a copy write notice to this as well which could cause problems if people do not remove the code.
All in all its a handy bit of code that even if i dont use on this website i can see its application on others so thought I would share.
Blog post by Alex Wells
Working as a Website developer I love nothing more then working waist deep in code, I have specific interests in PHP and WordPress development but mostly working with local businesses to provide them with a website that meets their needs. Contact me if you have a project in mind and would like to get an input from an experienced website developer.
