In today’s digital world, protecting your website’s content from unauthorized copying is crucial, especially if you run a blog or an informational website. Many users seek ways to prevent visitors from copying their text and pasting it elsewhere. While numerous WordPress plugins exist to disable copy-paste functionality, some website owners prefer a manual approach to keep their site lightweight and free from extra plugins.
In this article, we will show you how to disable copy and paste on WordPress without using a plugin by adding custom JavaScript and CSS code.
Read More: How to Create a Top Notification Bar in GeneratePress Theme
Why Disable Copy and Paste?
Before diving into the technical steps, let’s explore why you might want to disable copy-paste functionality:
- Prevent Content Theft – Your blog posts, articles, or unique website content may be copied and used without your permission.
- Protect SEO Efforts – Duplicate content can harm your SEO rankings if others steal and republish your text.
- Enhance Website Security – Disabling right-click and keyboard shortcuts can help prevent malicious users from easily copying sensitive information.
Now, let’s explore how you can implement these restrictions manually.
Method 1: Disable Copy and Paste Using JavaScript
JavaScript can help you block users from copying content by disabling right-click and keyboard shortcuts.
Steps to Add JavaScript in WordPress
- Log in to your WordPress dashboard.
- Navigate to Appearance → Theme Editor.
- Open the functions.php file and add the following script:
function disable_copy_paste() {
echo '<script>
document.addEventListener("copy", function(e) {
e.preventDefault();
alert("Copying content is disabled!");
});
document.addEventListener("cut", function(e) {
e.preventDefault();
alert("Cutting content is disabled!");
});
document.addEventListener("contextmenu", function(e) {
e.preventDefault();
alert("Right-click is disabled!");
});
</script>';
}
add_action("wp_head", "disable_copy_paste");
This script prevents users from copying, cutting, or right-clicking on your website content.
Method 2: Prevent Text Selection Using CSS
Another effective way to discourage copying is by preventing text selection with CSS.
Steps to Add CSS in WordPress
- Go to Appearance → Customize → Additional CSS.
- Add the following CSS code:
body {
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}
This code ensures that users cannot highlight and copy text from your website.
Method 3: Block Keyboard Shortcuts
Many users copy content using keyboard shortcuts like Ctrl + C
, Ctrl + X
, or Ctrl + V
. You can block these actions using JavaScript.
Steps to Add JavaScript in WordPress Footer
- Navigate to Appearance → Theme Editor.
- Open the footer.php file.
- Add the following script before the closing
</body>
tag:
<script>
document.onkeydown = function(e) {
if (e.ctrlKey && (e.key === "c" || e.key === "x" || e.key === "v")) {
alert("Keyboard shortcuts are disabled!");
return false;
}
};
</script>
This script disables common keyboard shortcuts for copying and pasting.
Final Thoughts
Disabling copy and paste on your WordPress website without a plugin is a straightforward process using JavaScript and CSS. While these methods help prevent casual users from stealing content, keep in mind that determined individuals can still bypass these restrictions. If protecting your content is a major concern, consider watermarking images, using copyright notices, or setting up DMCA protection.
Would you like more WordPress tips and tricks? Stay tuned for more insightful guides!