I have added function code in my WordPress for copy text, what I need now is to limit the word count to my desired range for copied text, no matter how much long paragraphs user copies.
Here is the current code :
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 beforepagelink = "Before Text: "
var pagelink = "<?php the_title(); ?> <br /><br /><a href='<?php echo wp_get_shortlink(get_the_ID()); ?>'><?php echo wp_get_shortlink(get_the_ID()); ?></a><br />Source: Jamkhed Times"; //Change this if you like
var afterpagelink = "<br /><br /> after text";
var copy_text = beforepagelink + selection + pagelink + afterpagelink;
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');
If anyone can suggest me an update then it will make my day! Thanks!!