Wordpress automatically adds copyright information when copying an article

Source: Internet
Author: User

Copy the following code and put it in single. php. The location can generally be placed under the content code of the article. When others copy the content of the article, the system will attach the copyright information.

The code is as follows: Copy code

<Script type = "text/javascript">
Document. body. oncopy = function (){
Event. returnValue = false;
Var t = document. selection. createRange (). text;
Var s = "this article comes from <? Php bloginfo ('name');?> <? Php echo get_settings ('Home');?> , Original address: <? Php the_permalink ()?> ";
ClipboardData. setData ('text', 'RN '+ t + 'RN' + s + 'RN ');
}
</Script>

Note: This method is only applicable to IE browsers. If you need to be compatible with the code instructions of all browsers, see the following example.

As we all know, browsers such as IE, Firefox, and Google are mostly used by webmasters. The popular browsers such as Sogou, and Aoyou are still popular in the 360 s. Is there any code compatible with all browsers? The answer is yes! This JS code is not only applicable to WordPress, but also to a variety of popular open-source programs. The friends who need to use it should remember Mark quickly.

The code is as follows: Copy code

Function addLink (){

Var body_element = document. getElementsByTagName_r ('body') [0];

Var selection;

Selection = window. getSelection ();

Var pagelink = "this article is transferred from: + document. location. href +" '> "+ document. location. href +" www.111cn.net "; // change this if you want

Var copytext = selection + pagelink;

Var newdiv = document. createElement_x ('div ');

Newdiv. style. position = 'absolute ';

Newdiv. style. left = '-99999px ';

Body_element.appendChild (newdiv );

Newdiv. innerHTML = copytext;

Selection. selectAllChildren (newdiv );

Window. setTimeout (function (){

Body_element.removeChild (newdiv );

}, 0 );

}

Document. oncopy = addLink;

Note: put it in footer. php for the whole site, and put it in single. php for the article page only. You can modify the text in the code on your own.

 

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.