I wanted to disable right click on my wordpress site. I have written a small snippet and inserted into body which disables right click, CTRL events and keyups.
<body oncontextmenu="return false" onselectstart="return false" onkeydown="if ((arguments[0] || window.event).ctrlKey) return false"></body>
but it is annoying when I want to copy something on site. is there a way I can modify the current snippet like only logged in users would be able to access the disabled events?
Cheers.
4
Answers
First I have created a JS page in the directory named: "preventcopy.js" and added restricted the events using below JS
and then in function.php I enabled access for logged in users as below.
That's how it is been accomplished. But I would highly suggest enabling these features for users considering the user experience.
Why not using existing wordpress plugin?
for example using this
This plugin is used to disable right click on website to prevent cut, copy, paste, save image, view source, inspect element etc.
But when Administrator or Site Editor is logged in, he can access everything without any of the above restrictions.
You could simply put a conditional inside the body tag. You would want this in your theme’s header.php file. You also want the wordpress function
body_class
to include all of the other classes that should appear in the body tag.Just disable context menu not select or other events.