现在文章不管写的有多好是否原创只要被人简单的复制粘贴就被人轻松的拿去当自己的原创了还不加上版权信息,如果禁用复制功能觉得不利于用户的体验,因为本站就是提供一些开源代码学习的,这里可以使用以下代码功能是复制内容同时自动添加文章链接和自定文字。将以下代码复制到 functions.php 文件中:
[code]function add_copyright_text() {
if (is_single()) { ?>
<script type=’text/javascript’>
function addLink() {
if (
window.getSelection().containsNode(
document.getElementsByClassName(‘entry-content’)[0], true)) {
var body_element = document.getElementsByTagName(‘body’)[0];
var selection;
selection = window.getSelection();
var oldselection = selection
var pagelink = “<br /><br /> 阅读更多: <?php the_title(); ?> <a href='<?php echo get_permalink(get_the_ID()); ?>’><?php echo get_permalink(get_the_ID()); ?></a>”; //根据你的需要修改这行代码
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’);[/code]