Get a Link Back to Your WordPress Site from Copy & Pasted Text

Get a Link Back to Your WordPress Site from Copy & Pasted Text

Did you know that copying and pasting makes up 82% of all content sharing on the web — 4.5 times more than social sharing buttons?

That’s what advertising giant 33across/Tynt found in a study done at the end of last year.

You may find that interesting. But so what? How can you use that information for your own site? Read on to find out.

Get a Link Back from Copy & Pasted Text

Have you ever copied a piece of text from a website into an email, a file, a forum, or even onto your own site, and suddenly you notice that appended to the end of the text was a link back to the page where it came from?

Pretty cool, right? And when you think about it, pretty good for SEO purposes too. Well, that’s what this little piece of code below will let you achieve for your own site.

If you paste this in as is, it will show a link back to the page with the following style. Let’s say your post is titled “Little Orange Squares” and your site is mysite.com.

Read more: Little Orange Squares http://mysite.com/little-orange-squares/

You can change this to say something like “Read more at MySite” by just adding what you’d like at the end of the “Read more” text.

Paste the following into your functions.php file (Appearance > Editor > Theme Functions – functions.php).

FREE EBOOK
Your step-by-step roadmap to a profitable web dev business. From landing more clients to scaling like crazy.

By downloading this ebook I consent to occasionally receive emails from WPMU DEV.
We keep your email 100% private and do not spam.

FREE EBOOK
Plan, build, and launch your next WP site without a hitch. Our checklist makes the process easy and repeatable.

By downloading this ebook I consent to occasionally receive emails from WPMU DEV.
We keep your email 100% private and do not spam.

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 pagelink = "<br /><br /> Read more at YourSiteName: <?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_copyright_text');

If you are using a link shortening service, then you can use the code above with it, but replace get_permalink with wp_get_shortlink.

If you would like to make your own simple plugin for this code, you can learn how to do that here.

Code source: WPBeginner

Photo: Chain Link Close Up from BigStock

Tags: