Disabling copy and paste on your WordPress site can be useful for protecting your content from being copied without permission. While completely preventing copying is challenging without plugins, you can implement measures to discourage casual copying. Here’s a method to disable copy and paste using HTML and CSS:
Step 1: Add CSS to Disable Selection
Place the following CSS code in your WordPress theme's stylesheet or in the Customizer (if your theme allows custom CSS):
body {
-webkit-touch-callout: none; /* iOS Safari */
-webkit-user-select: none; /* Safari */
-khtml-user-select: none; /* Konqueror HTML */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
user-select: none; /* Non-prefixed version, currently supported by Chrome, Edge, Opera, and Firefox */
}
Step 2: Customize the Message (Optional)
Add a message to inform users why copying is disabled:
<div class="copy-message">
Copying content from this site is not allowed.
</div>
Style the message using CSS:
.copy-message {
display: none;
position: fixed;
bottom: 10px;
left: 50%;
transform: translateX(-50%);
background-color: #ffcccc;
padding: 10px;
border: 1px solid #ff6666;
border-radius: 5px;
font-size: 14px;
text-align: center;
z-index: 9999;
}
body::before {
content: '';
display: block;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 9998;
background-color: transparent;
pointer-events: none;
}
body.no-copy::before {
background-color: rgba(255, 255, 255, 0.8);
}
body.no-copy .copy-message {
display: block;
}
Step 3: Add JavaScript (Optional)
While CSS can prevent most users from selecting and copying text, it’s not foolproof. For stronger protection, you can add JavaScript to further disable right-click and keyboard shortcuts:
<script type="text/javascript">
document.addEventListener('contextmenu', function(e) {
e.preventDefault();
});
document.addEventListener('keydown', function(e) {
if (e.ctrlKey && (e.keyCode === 67 || e.keyCode === 86 || e.keyCode === 85 || e.keyCode === 117)) {
e.preventDefault();
}
});
</script>
Place this script in the footer of your WordPress theme, just before the closing </body> tag.
Step 4: Test and Adjust
Test your site to ensure copying and pasting is effectively disabled. Adjust the CSS and JavaScript as needed to achieve the desired level of protection without compromising user experience.
Considerations
Keep in mind that while these methods can deter casual copying, determined users can still find ways to copy content. Balance protection with user accessibility and the overall user experience of your WordPress site.

Post a Comment