以下代码放到模板根目录下的 functions.php 里
- //复制文字自动添加版权信息
- function v7v3_copyright() {
- ?>
- <script type=’text/javascript’>
- function addLink() {
- var body_element = document.getElementsByTagName(‘body’)[0];
- var selection;
- selection = window.getSelection();
- var pagelink = “<br /><br /> 本文来源于:<?php bloginfo(‘name’); ?>。<br />原文标题: <?php if(is_single()){ the_title();}?><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
- }
- add_action( ‘wp_head’, ‘v7v3_copyright’);
如果需要弹窗,在模板根目录下的single.php 添加如下代码:
- <script type=“text/javascript”>
- document.body.oncopy=function(){alert(“复制成功!若要转载请务必保留原文链接,申明来源,谢谢合作!”);}
- </script>
亲爱的:被墙域名跳转TG:@qianhenetwork QQ:851617266,可否收藏+评论+分享呢?
文章评论 本文章有个评论