WordPress网站文章复制自动加上文章网址出处链接

WordPress网站文章复制自动加上文章网址出处链接,找到主题目录下的functions.php文件,在次文件里面添加以下代码即可:

function add_copyright_text() { ?>
<script type=’text/javascript’>
function addLink() {
var body_element = document.getElementsByTagName(‘body’)[0];
var selection;
selection = window.getSelection();
var pagelink = “<br /><br /> 转载请注明来源,本文来自: <a href='”+document.location.href+”‘>”+document.location.href+”</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
}

这个功能虽然没什么用但还是有的。

© 版权声明
THE END
站务请联系QQ:190323122 微信:m86878
点赞74 分享