WordPress文章防复制代码的方法
通过下面的JS代码,可以有效地防止别人直接复制拷贝你的文章,用frame标签引用你的文章时,会自动跳转到文章正常链接,同时禁止右键菜单。
使用方法一:
打开当前主题头部模板header.php找到:<?php wp_head(); ?>将下面代码添加到后面:
<script> // 禁止右键 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); } </script>
使用方法二:
上面的方法查看源代码时有些乱,可以在当前主题目录新建一个名称为copyright.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('copyright', get_template_directory_uri() . '/copyright.js', array(), false); } if (!current_user_can('level_10')) { add_action( 'wp_enqueue_scripts', 'copyrightpro_scripts' ); }
代码中加了判断,管理员登录状态一下,防复制代码无效。
当然上面的方法,也只是忽悠一下小白,浏览器禁用JavaScript后,将失去效果。
你可能还喜欢下面这些文章

很久之前开发过一个文章去重插件,由于需要生成文章指纹,而生成指纹又依赖分词。分词的速度是比较慢的,因此去重插件用起来体验不太好。仔细一下,其实生成文章指纹并不需要那么精确的分词。

网站获取流量需要依靠长尾词,但我们不可能把所有的长尾词都堆在标题或者正文中。现在我开发了一款能自动匹配长尾词的插件wpkws,他的功能是找到和文章相似的长尾词,自动添加为标签。

为了让wordpress更好用,我们开发了一款wp工具箱插件。imwpf提供 免登录发布接口、优化工具箱(定时任务开关,修订版开关,wp-json开关,缩略图开关)、防垃圾评论、后台文章分类标签ID显示、百度推送、收录快捷查看 功能,并且还在

WordPress文章编辑器页面右侧的分类展示使用的是wp_terms_checklist()函数。该函数用于显示一个包含分类目录或标签的复选框菜单,允许用户在文章编辑页面中选择相关的分类或标签。

现在可以用定时发文插件来解决这个问题啦!WordPress具有定期发布文章的功能。有时候我们使用wordpress定时发布的时候,会发布失败,这是因为WordPress默认发布文章的时间是0.01秒,一旦超过这个时间而没有发布成功,定时发布文

wordpress后台不显示摘要function new_excerpt_more($more) {a href=””. get_permalink($post->

让WordPress一个页面显示全部分类的文章cat=’ . $cat->php echo $cat->a href=”<$cats = get_categories(array(‘include’ =>