The article link code is automatically added after the content is copied

Source: Internet
Author: User

Specific methods

You can add a feature to your WordPress site: After the content is copied, post links are added automatically after pasting.

Add the following code to the functions.php file for the topic:

The code is as follows Copy Code

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: <?php the_title ();?> <a href= ' <?php echo get_permalink (get_the _ID ());?> ' ><?php echo get_permalink (get_the_id ());?></a> "; Modify this line of code according to your needs
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 do not want to modify the PHP file we can directly use the JS implementation, and do not need to increase the code as above

The code is as follows Copy Code


<script type= "Text/javascript" >
Document.body.oncopy = function () {
settimeout (function ()
{
var text = clipboarddata.getdata ("text");
if (text) {
Text = text + "RN This article originates from [Left Bank] (http://www.111cn.net) Source:" +LOCATION.HREF;
Clipboarddata.setdata ("text", text);
}
}, 100)
}
</script>

For more details please see: http://www.111cn.net/wy/js-ajax/34745.htm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.