This is a very simple code by @rickymccallum87 from wordpress.org support. It is JavaScript. I installed the plugin Insert Headers and Footers by WPBeginner and put the following code into “Scripts in the footer”:
<script> /** * Prevents right click on images, by disabling contextmenu. **/ // Get all html elements with the tag 'img', i.e. all the images. The result is the array IMAGES of objects var images = document.getElementsByTagName('img'); //for all the images in the array for(var i = 0; i < images.length; i++) { /** If the context menu - by default activated by right-click - should be activated, * the default action is prevented * */ images[i].addEventListener('contextmenu', event => event.preventDefault()); } </script>
Wondering what the event => event.preventDefault()
means? It is an arrow function and it replaces an anonymus function and here is the step by step conversion, from the Mozilla’s site:
event => event.preventDefault()
Is the same as
(event) => event.preventDefault()
Which is the same as
(event) => {event.preventDefault()}
Which is the same as the anonymous function
function(event){ return event.preventDefault(); }
I applied it on the page of the photographer Lubka, on her wish.