Advertisement
tzvij

Copy and Paste plugin full

Aug 12th, 2013
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.47 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Copy and Paste Add-on
  4. Plugin URI: N/A
  5. Description: Adds on text to any copy and paste which backlinks to the specified site.
  6. Original Code for Plugin Template: http://wpmu.org/how-to-create-your-own-super-simple-wordpress-plugins/
  7. Original Code for Copy and Paste: http://www.wpbeginner.com/wp-tutorials/how-to-add-a-read-more-link-to-copied-text-in-wordpress/
  8. Version: 1.0
  9. Author: Tzvi Joffre
  10. Author URI: N/A
  11. License: GPL2
  12. */
  13.  
  14. if (is_single()) { ?>
  15.  
  16. <script type='text/javascript'>
  17. function addLink() {
  18.     if (
  19. window.getSelection().containsNode(
  20. document.getElementsByClassName('entry-content')[0], true)) {
  21.     var body_element = document.getElementsByTagName('body')[0];
  22.     var selection;
  23.     selection = window.getSelection();
  24.     var oldselection = selection
  25.     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>"; //Change this if you like
  26.     var copy_text = selection + pagelink;
  27.     var new_div = document.createElement('div');
  28.     new_div.style.left='-99999px';
  29.     new_div.style.position='absolute';
  30.  
  31.     body_element.appendChild(new_div );
  32.     new_div.innerHTML = copy_text ;
  33.     selection.selectAllChildren(new_div );
  34.     window.setTimeout(function() {
  35.         body_element.removeChild(new_div );
  36.     },0);
  37. }
  38.  
  39. document.oncopy = addLink;
  40. </script>
  41.  
  42. <?php
  43. }
  44. }
  45.  
  46. add_action( 'wp_head', 'add_copyright_text'); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement