After recently finishing a project for an architectural firm, there was a simple request from the architect. Texts and other contents can be dragged and right-clicked, but we are requesting that right-clicking on the most important asset, ‘photos’, be prevented.
In fact, considering that other than right-clicking on photos uses the inspection function of developer tools, it is correct to prevent right-clicking on the entire site content. However, when search robots read it, they may get lost and right click prevention cause some problems with your site’s SEO.
In consideration of the above problems, at the request of architects, we would like to introduce a method that prevents right-clicking on only photos.
STEP 1. Access the FTP of the WordPress theme you are using.
You’ve probably seen a screen like the one above. Then, access the ‘Theme’ folder in the following order: www > wp-content > themes.
How to edit style.css, not footer right click prevention
This method is also a way to edit files within the child theme. Cameroon Mobile Number List
To use the right-click prevention feature, insert the following code into theme style.css.
STEP 2. Open the child theme
I am using the elementor theme, which is a very light theme. When you access the elementor theme’s right click prevention child theme, at first there are only style.css, screenshot.png, readme.txt, and function.php files.
Please add a new footer.php file here.
By using an FTP tool such as FileZilla and clicking on the blank screen of the folder, you can create a new file as if you were creating a folder in Windows. After setting the file name to footer.php, copy and paste the contents of the footer.php file from the original theme.
STPE 3. Add script right click prevention
If you created a footer file, insert the following script at the very bottom of the theme footer.
<script>
document.addEventListener('contextmenu', function (event) {
if (event.target.tagName === 'IMG') {
event.preventDefault();
}
});
</script>
Afterwards, save the file and click ‘Save’ when asked to confirm whether you want to save the changes via FTP.
Now, if you go to the site and right-click on the photo, you can see that the right-click prevention function works well and the image copy function is no longer possible.