How to Disable Text Selection Copy/Paste and Context Menu on right mouse button click in WordPress

How To Disable Text Selection, Copy/Paste, And Right-click In WordPress

We put so much effort and energy into creating attractive and unique content on our site for our audiences. But what if you find your contents getting stolen and used without your permission? Now you might be thinking about how you can make it difficult for thieves to steal your site’s resources! To prevent your content from getting stolen you need to disable text selection, copy/paste, and right-click. So today we will show you a set of ways you can easily disable text selection, copy/paste, and right-click in WordPress.

Disable Text Selection Using JavaScript:

Using JavaScript to disable text selection, copy/paste, and the right-click button in WordPress is the most popular method on the web. To enable this method, go to Appearance > Theme Editor. Now, on the left side, you will see Theme Files. Choose the Theme Functions (functions.php) file there.

text selection and copy protection with javascript
Content Copy Protection with JavaScript

Now add the following code on the bottom of the left side code box.

function your_function() {
   ?>
<script>
jQuery(document).ready(function(){
function disableselect(e) {
  return false;
};

function reEnable() {
  return true;
};

document.onselectstart = new Function ("return false")

if (window.sidebar) {
  document.onmousedown = disableselect
  document.onclick = reEnable
};

    jQuery(document).bind("contextmenu",function(e){
        return false;
    });
    jQuery(document).bind("copy",function(e){
        return false;
    });
   jQuery(document).bind("paste",function(e){
        return false;
    });
   jQuery(document).bind("select",function(e){
        return false;
    });
});
</script>
<?php
}
add_action('wp_footer', 'your_function');

Click on Update File to save the code on your Theme Function file.

content protection with javascript
Content Copy Protection with JavaScript

This code will enable all options to protect your content from thieves.

Disable Text Selection with CSS Code:

In this method, you need to add some custom CSS code to your WordPress site. Simply go to Appearance > Customize, where you will get options for customizing your WordPress site. Click on the last option Additional CSS.

content protection with CSS
Content Copy Protection with CSS

You will get a box for adding code after clicking Additional CSS. Add the code, given below to that box.

body {
-webkit-user-select: none;  /* Chrome all / Safari all */
-moz-user-select: none;  /* Firefox all */
-ms-user-select: none;   /* IE 10+ */
-o-user-select: none;
user-select: none;
}

Click the Publish button to save this code on your site.

content protection with CSS
Content Copy Protection with CSS

Now check if you can select and copy/paste. In this method, you will be able to right-click but won’t be able to see the copy option.

Disable Text Selection Using Plugin:

The best thing about WordPress is you will get lots of plugins for every feature you need to add to your site. You will also get a lot of plugins for disabling text selection, copy/paste, and context menus.

Search for the plugin WP Content Copy Protection & No Right Click, then install and activate the plugin.

text selection and copy protection with plugin
WP Content Copy Protection Plugin

After activating, this plugin disables text selection, copy/paste, and the right-click button automatically. But if you want to change any setting, you just need to go to the Copy Protection page on your admin dashboard. There, you will get various protection options with different protection layers for specific pages and posts, and make changes as per your requirement. You can also change Selection disabled and Print preview messages there. Don’t forget to click on the Save Settings button after making any changes.

text selection and copy protection with plugin
WP Content Copy Protection Plugin

This method is easier to implement and also gives your content more security than other methods.

When you disable the text selection, copy/paste, and right-click, you not only prevent your content from stealing but also prevent them from viewing your site’s code using the Inspect command. However, you may always not benefit from using these functions. For example, if I disable the text selection, copy/paste, and right-click on this blog, many people won’t be able to copy the codes I’ve given out here. This can cause discomfort for visitors. So use these functions carefully. For more informative articles like this, don’t forget to visit our blog page.


Leave a Reply