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