Tuesday, June 12, 2012

Wordpress for Beginners

Wordpress for Beginners


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

Posted: 11 Jun 2012 06:36 AM PDT

You may have noticed how some popular websites (like eHow etc) will attach a “read more” link to any text that is copied from their site. This is a great way to get new users. Often folks are copying and pasting text from websites into email. Some use it to save the information for future, while others are just sharing it with their friends, family, and colleagues. In this article we are going to show you how you can easily add a “read more” link to any copied text from your WordPress blog, so you can get additional traffic.

Note: To see this in action, copy anything on this post and paste it in your email or notepad.

First thing you need to do is copy the following code into your theme’s functions.php file or a site-specific plugin:

  function add_copyright_text() { ?>    <script type='text/javascript'>  function addLink() {      var body_element = document.getElementsByTagName('body')[0];      var selection;      selection = window.getSelection();      var pagelink = "<br /><br /> Read more at WPBeginner: <?php if(is_single()){ the_title();}?> <a href='"+document.location.href+"'>"+document.location.href+"</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, whenever someone comes to your website and tries to copy your content a read more link will be included along with it. Don’t forget to change the copyright text, and add your own site’s title there.

How To Add a Read More Link to Copied Text in WordPress is a post from: WPBeginner which is not allowed to be copied on other sites.

No comments:

Post a Comment

Search This Blog

Top WordPress Seller