WordPress站點(diǎn)內(nèi)容被別人復(fù)制是常有的事,你可以給你的WordPress站點(diǎn)添加一個(gè)功能:內(nèi)容被復(fù)制后,粘貼的時(shí)候自動(dòng)在后面添加文章鏈接。
將下面的代碼添加到主題的 functions.php 文件中:
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>"; //根據(jù)你的需要修改這行代碼
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');
好了,就真么簡單,不過是防防君子罷了。
參考資料:http://www.wpbeginner.com/wp-tutorials/how-to-add-a-read-more-link-to-copied-text-in-wordpress/
聲明:本站所有文章,如無特殊說明或標(biāo)注,均為本站原創(chuàng)發(fā)布。任何個(gè)人或組織,在未征得本站同意時(shí),禁止復(fù)制、盜用、采集、發(fā)布本站內(nèi)容到任何網(wǎng)站、書籍等各類媒體平臺(tái)。如若本站內(nèi)容侵犯了原著者的合法權(quán)益,可聯(lián)系我們進(jìn)行處理。





添加代碼之后網(wǎng)站不能訪問,沒有添加到<?php 里面
添加到 functions.php 的最后面(如果最后面有 ?> ,就添加到它的前面,如果沒有,直接添加)。建議看看 http://www.ydqwiac.cn/wordpress-functions-php.html
成功了,謝謝
防君子,哈哈。。
這個(gè)可以有
對(duì)于小人尼