有时候自己辛辛苦苦的原创文章放在博客上,立马就能被一些人抄袭或采集,虽然我们无法从根源上防止这种情况的发生,不过我们可以加大人家抄袭我们网站文章的难度。
一、使用代码禁止复制
在WordPress当前主题目录新建一个js文件,取名为fuzhi.js,并将添加以下代码:
// 禁止右键 document.oncontextmenu = function() { return false }; // 禁止图片拖放 document.ondragstart = function() { return false }; // 禁止选择文本 document.onselectstart = function() { if (event.srcElement.type != "text" && event.srcElement.type != "textarea" && event.srcElement.type != "password") return false; else return true; }; if (window.sidebar) { document.onmousedown = function(e) { var obj = e.target; if (obj.tagName.toUpperCase() == "INPUT" || obj.tagName.toUpperCase() == "TEXTAREA" || obj.tagName.toUpperCase() == "PASSWORD") return true; else return false; } }; // 禁止frame标签引用 if (parent.frames.length > 0) top.location.replace(document.location);
接着在functions.php文件最下方添加代码:
function copyrightpro_scripts() { wp_enqueue_script( 'fuzhi', get_template_directory_uri() . '/fuzhi.js', array(), false ); } if (! current_user_can('level_10') ) { add_action( 'wp_enqueue_scripts', 'copyrightpro_scripts' ); }
保存后在网站强制刷新,就可以发现已经无法在右键,或者快捷查看源代码了。
二、安装插件禁止复制
或者可以直接在插件市场,下载CopyRightPro插件,启用就可以达到禁止复制的效果。
当然,本站启用了禁止复制,以后我会停止这个功能;毕竟复制,有时候更利于帮助到大家。