wordpress主题纯代码禁止复制文章内容的方法

maolai 网站建设评论340阅读模式

wordpress主题纯代码禁止复制粘贴文章内容的方法,wordpress不利用插件如何限制文章被复制,禁止鼠标右键复制内容。

一些新手站长很喜欢复制别人网站原创的文章,新的文章别人复制的已经收录了,反而你网站内容的还没收录,这种抄袭很不好。如下是WordPress主题防止文章内容复制的一些代码。

方法一:将以下js代码放在你主题的header.php文件内,保存后可以实现网页禁止右键、禁止查看源代码、禁止复制的代码

<script type="text/javascript">
document.oncontextmenu=new Function('event.returnValue=false;');
document.onselectstart=new Function('event.returnValue=false;');
 </script>

第二种方法:在当前用的wordpress主题根目录创建一个名称copyright.js文件,将以下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);

将以下js代码复制粘贴到你前wordpress模板的函数模板functions.php文件的最后面

//防复制
function copyrightpro_scripts() {
    wp_enqueue_script( 'copyright', get_template_directory_uri() . '/copyright.js', array(),  false );
}
if (! current_user_can('level_10') ) {
add_action( 'wp_enqueue_scripts', 'copyrightpro_scripts' );
}

js下载链接: https://pan.baidu.com/s/1ZjcHEFj_ncSgrs9BczVbew?pwd=vxya 提取码: vxya

 
maolai
  • 本文由 maolai 发表于 2018年5月8日 02:24:11
  • 转载请务必保留本文链接:http://www.bokequ.com/435.html

发表评论