Family Best Time >> Electronics

How to add a Read More link to copied text in WordPress

You may have noticed how some popular websites (such as eHow, etc.) will attach a "read more" link to any text that is copied from their site. This is a great way to get new users. People are often copying and pasting text from websites into emails. Some use it to save information for the future, while others only share it with their friends, family, and colleagues. In this article, we will show you how you can easily add a “read more” link to any text copied from your WordPress blog, so you can get extra traffic.

Note:To see this in action, copy anything in this post and paste it into your email or notepad.

The first thing you need to do is copy the following code into your theme's functions.php file or a site-specific plugin:

 function add_copyright_text () if (is_single ()) ?> function addLink () if (window.getSelection (). contieneNodo (document.getElementsByClassName ('entry-content') [0], true)) var body_element = document.getElementsByTagName ('body') [0]; selección de var; selection = window.getSelection (); var oldselection = selection var pagelink = "

Lea más en WPBeginner: "; // Cambie esto si desea 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 agregar enlace;

Now, whenever someone visits your website and tries to copy your content, a read more link will be included along with it. Don't forget to change the copyright text and add your own site's title there.

Edit:We were initially grabbing the URL from the window, but as one of our users pointed out he made the URLs look clunky. We have updated the code to only display it on single post pages and use wp_shortlink. So you would use something like this:yoursite.com/?p=23. If you are using a custom shortlink like us:wpbeg.in, then the branded shortlink will be displayed.