Monday, November 30, 2020
Home Blogging How To Add a Read More Link to Copied Text in WordPress

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

You’ll have observed how some widespread web sites (like eHow and so forth) will connect a “read more” hyperlink to any textual content that’s copied from their website. This can be a nice option to get new customers. Typically of us are copying and pasting textual content from web sites into e mail. Some use it to save lots of the knowledge for future, whereas others are simply sharing it with their associates, household, and colleagues. On this article we’re going to present you how one can simply add a “read more” hyperlink to any copied textual content out of your WordPress weblog, so you will get further visitors.

Notice: To see this in motion, copy something on this publish and paste it in your e mail or notepad.

Very first thing you’ll want to do is copy the next code into your theme’s capabilities.php file or a site-specific plugin:

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
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 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 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');

Now, at any time when somebody involves your web site and tries to repeat your content material a read more hyperlink shall be included together with it. Don’t overlook to vary the copyright textual content, and add your personal website’s title there.

You May Also Like : How to Embed SWF in Your WordPress Posts

Edit: Initially we had been grabbing the window URL, however as one among our customers identified that it made the URLs look clunky. We’ve up to date the code to solely present it on single publish pages, and use gy_shortlink. So it might use one thing like this: yoursite.com/?p=23. If you’re utilizing a custom-made shortlink like we’re: gyanhi.in, then it’ll present the branded shortlink.

If you liked this article, make sure to hit the bell for getting our latest updates and share this article with your friends in every social media platforms.

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

How to Signup for Godaddy Affiliate Program & Start Making Money

GoDaddy is likely one of the well-liked model names out there of area and web-hosting. They are well-liked for a numerous cause, and so they...

How To Start Selling Website on Flippa: A Beginner’s Guide To Success

If you may have been working on-line for lengthy and into Website flipping, Flippa is one identify that you need to have heard of. Flippa is a...

How to Fix Your Connection is Not Private Error (Site Owners Guide)

Are you seeing ‘Your connection is not private’ error in your WordPress web site? This is the error message you’ll see on Google Chrome. The...

How to Fix the WordPress White Page of Death (Step by Step)

The WordPress white page of dying is one of the most widespread WordPress errors. It can also be one of the most irritating ones as...

Recent Comments