# 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.

- Type: JavaScript
- Runs: Site-wide footer
- Category: [Media](https://wpide.com/library/category/media/)
- Tags: images, protection, copyright
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/disable-right-click-on-images/

## Code

```javascript
(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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Disable Right-Click and Dragging on Images" in its snippet library and add it in one click; or create a new JavaScript snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
