Disable Right-Click and Dragging on Images
Stops visitors from right-clicking or dragging images to save them, a simple deterrent for photographers and artists.
Opens WPIDE on
Code
(function () {
function isImage(target) {
return target && target.tagName === 'IMG';
}
document.addEventListener('contextmenu', function (event) {
if (isImage(event.target)) {
event.preventDefault();
}
});
document.addEventListener('dragstart', function (event) {
if (isImage(event.target)) {
event.preventDefault();
}
});
})();
Notes
This only discourages casual copying; images can still be saved through browser tools or screenshots.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.