最近在一個網(wǎng)站復制該網(wǎng)站的內(nèi)容時會自動添加一個版權,,這功能感覺挺不錯,,雖然不能防止別人復制自己網(wǎng)站的文章但是至少可以給他一個注明版權的提醒,。
那么wordpress系統(tǒng)的網(wǎng)站如何來實現(xiàn)這個功能呢,?下面給出兩個實現(xiàn)wordpress文章被復制添加版權方法:
方法一:復制下面的代碼到主題的functions.php文件中
function zyku_copyright() { ?><script type='text/javascript'>function addlink() { var body_element = document.getElementsByTagName('body')[0]; var selection; selection = window.getSelection(); var pagelink = "<br /><br /> 原文信息: <?php if(is_single()){ the_title();}?> 原文鏈接:<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}add_action( 'wp_head', 'zyku_copyright');
方法二:復制以下代碼到到主題的header.php文件中
<script type='text/javascript'>function addlink() { var body_element = document.getElementsByTagName('body')[0]; var selection; selection = window.getSelection(); var pagelink = "<br /><br /> 原文信息: <?php if(is_single()){ the_title();}?> 原文鏈接:<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>