Some popular websites have some tricks to attach a ‘read more’ link or ‘copyright link’ to any text, while its content is copied. It is a good way to get more visitors, also promote yours website. Since copying and pasting text will be embedded with some information about itself webpage. So while folks are just sharing it with their colleagues, family, or friends.
Here are a few codes to make this happen, add a ‘read more’ link from your WordPress blog into any copied text. First thing you need to know this trick is just copy the following code and pasting it into your theme’s 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 29 30 31 32 33 34 35 36 37 38 39 |
function add_readmore_text() { if (is_single()) { ?> <script type='text/javascript'> function addLink() { if ( window.getSelection().containsNode( document.getElementsByClassName('catTagNews')[0], true)) { var body_element = document.getElementsByTagName('body')[0]; var selection; selection = window.getSelection(); var oldselection = selection var pagelink = "<br /><br /> Read more at YouCanFree.Com: <?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_readmore_text'); |
add_action( ‘wp_head’, ‘add_readmore_text’);
Note: make sure you have catTagNews class on your theme or you can change it with your theme. Also, don’t forget to change the copyright link and text on this code.
Just copy anything on this post and voila, paste it in notepad or your email. Now, you can see this in action.