Latest Tech and Tips

How To Add a Read More Link to Copied Text in WordPress

1

You might have observed how some prominent internet sites (like eHow etc) will certainly connect a “read more” link to any type of text that is copied from their website. This is a fantastic method to obtain brand-new individuals. Often people are replicating and also pasting text from internet sites right into e-mail. Some utilize it to save the info for future, while others are simply sharing it with their close friends, family members, and also associates. In this short article we are going to reveal you how you can conveniently add a “read more” link to any type of copied text from your WordPress blog site, so you can obtain added website traffic.

Note: To see this in activity, duplicate anything on this blog post and also paste it in your e-mail or note pad.

First point you require to do is duplicate the complying with code right into your style’s functions.php documents or a site-specific plugin:

feature add_copyright_text() {
if (is_single()) {?>>.

<< manuscript kind=' text/javascript'>
> feature addLink() {
if (.
window.getSelection(). containsNode(.
document.getElementsByClassName(' entry-content')[0], real)) {
var body_element = document.getElementsByTagName(' body')[0];.
var choice;.
choice = window.getSelection();.
var oldselection = choice.
var pagelink = "<br /><br /> Read more at WPBeginner: <?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 such as.
var copy_text = choice + pagelink;.
var new_div = document.createElement(' div');.
new_div. style.left=' -99999 px';
new_div. style.position=' outright';

body_element. appendChild( new_div );.
new_div. innerHTML = copy_text;.
selection.selectAllChildren( new_div );.
window.setTimeout( feature() {
body_element. removeChild( new_div );.
},0);.
}
}

document.oncopy = addLink;.
<. <