Recently one of our subscribers asked us how can he prevent his visitors from using the right click on their WordPress site.

Right-clicking allows a page to display a context menu that offers more options on a page or an item on a page. In this tutorial, we will see how to disable this feature.

Why disable right-click on a WordPress blog?

Many blogs often have their content stolen, which is immediately used elsewhere. Even though Google is already sanctioning those who copy the content (textual) other blogs to publish on theirs, it remains that the protection of images is not always penalized, and some do not hold back to use images of other blogs on theirs.

So, to protect your images, in addition to adding a watermark (which is optional), you can disable right-click (even though this practice has limitations).

Code to disable right-click

You will need to know how to create a WordPress Plugin. We wrote a tutorial on it and I think you can get away with it.

All you have to do is register a " hook "(crochet) on the action wp_footer To make our code appear at the end of each page of the blog.

     

 
function disSel(target){
if (typeof target.onselectstart!="undefined")
target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined")
target.style.MozUserSelect="none"
else
target.onmousedown=function(){return false}
target.style.cursor = "default"
}

 

window.onload = function () {
document.body.onselectstart = function () {
return false;
}
document.body.ondragstart = function () {
return false;
}
}

By adding this code and activating your blog, right-click should be disabled.

Some plugins to simplify the work

1 - No Right Click Images Plugin

no-right-click-image-plugin-wordpress

Download

Keep leeches from nicking your images with this handy plugin, which uses JavaScript to change the right-click action on IMG tags to turn off the context menu.

It disables the menu on images only, so that other right click items work normally.

The image uploaded using the WordPress media library can be opened by clicking on it in a new tab. In this tab, this image is not protected. To avoid this inconvenience, you should avoid adding a link on your images.

Additionally, some browsers prevent JavaScript from modifying the behavior of the context menu. To work around this problem, the plugin uses a replacement image which will be used briefly when the image is clicked.

2 - WP Content Copy Protection & No Right Click

wp-content-copy-protection-plugin-wordpress

Download

This plugin goes further in disabling the right click.

In addition to disabling the right click, "WP Content Copy Protection & No Right Click" allows you to disable the CTRL + A, CTRL + C, CTRL + X, CTRL + S or CTRL + V (and the equivalent keys on Mac OS X), as well as disable the ability to select text. This means that you can protect your images and texts.

This plugin adds a submenu to the admin sidebar where you can access some basic plugin options: home page protection using JavaScript, and static page protection.

You can also enable or disable CSS protection.

The basic features of this plugin are free, but you can upgrade to the premium version for more features like the ability to display alert messages and compatibility with WordPress themes.

The limits to this practice

For experienced users, there is a flaw in this system, it is the development tool available on each web browser. These tools allow you to disable JavaScript on the browser making protection scripts unnecessary.

I do not find it particularly important to focus on protecting your content. As for your images, you can use a watermark. We have a list of 10 plugins that will help you get there.

That's it for this tutorial. I hope you can better protect the content of your WordPress blog. Feel free to ask us questions in the comments or share the tutorial with your friends.