Tutorial on how to automatically add copyright information to WordPress when copying web page content

888u

Last update at :2024-03-13,Edit by888u

How does WordPress automatically add copyright information when copying web page content? When copying article content on Zhihu, a copyright link will automatically be included. Can this function be moved to the wordpress blog program? The answer is yes, although the functions are a bit simple in comparison, they are sufficient.

JS code implements the automatic copyright adding function imitating Zhihu

1. JS calling code:

2. Copyright code 1:

function addLink() { var selection = window.getSelection(); pagelink = ". The original text comes from [us]. Please keep the original link for reprinting: " + document.location.href; copytext = selection + pagelink; newdiv = document.createElement(‘div’); newdiv.style.position = ‘absolute’; newdiv.style.left = ‘-99999px’; document.body.appendChild(newdiv); newdiv.innerHTML = copytext; selection.selectAllChildren(newdiv); window.setTimeout(function () { document.body.removeChild(newdiv); }, 100); } document.oncopy = addLink;

3. Copyright code 2:

function addLink() { var body_element = document.body; var selection; selection = window.getSelection(); if (window.clipboardData) { // Internet Explorer var pagelink =”\r\n\r\n The original text comes from [us]. Please keep the original link for reprinting: “+document.location.href+””; var copytext = selection + pagelink; window.clipboardData.setData (“Text”, copytext); return false; } else { var pagelink = "The original text comes from [us]. Please keep the original link for reprinting: "+document.location.href+""; var copytext = selection + pagelink; var newdiv = document.createElement(‘div’); newdiv.style.position=’absolute’; newdiv.style.left=’-99999px’; body_element.appendChild(newdiv); newdiv.innerHTML = copytext; selection.selectAllChildren(newdiv); window.setTimeout(function() { body_element.removeChild(newdiv); },0); } } document.oncopy = addLink;

How to use:

Add the second paragraph of the "copyright code" above to the prompt position in the middle of the first paragraph of code, and then copy it entirely to the header.php or footer.php of your WordPress theme, if your theme background has custom code The options are even better.

For DUX themes, you can add [custom header code] in the theme settings:

The above code is suitable for sites such as WordPress or zblog. If it is a zblog site, remember to click [Clear Cache] and recompile the template] in the background.

Friendly reminder:

After modifying the template, remember to change the template encoding to: UTF-8 without BOM (no signature), otherwise the Chinese characters in the prompt will be garbled. It is recommended to use special editing tools, such as: Notepad++ (free) to edit and modify the theme template file .

Recommended site search: domain name query official website, US server website, Singapore server, proxy IP address, how to query domain name registration number, rent high-defense IP, US host purchase, virtual host server, domain name registration information query, website registration information,

Tutorial on how to automatically add copyright information to WordPress when copying web page content

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码