Discourage Copying Images and Text
Disables right-click and dragging on images, and optionally text selection in post content, to discourage casual copying of your work.
Opens WPIDE on
Code
<script>
(function () {
var blockTextSelection = false; // true: also prevent selecting text in post content.
document.addEventListener('contextmenu', function (e) {
if (e.target.tagName === 'IMG') { e.preventDefault(); }
});
document.addEventListener('dragstart', function (e) {
if (e.target.tagName === 'IMG') { e.preventDefault(); }
});
if (blockTextSelection) {
var style = document.createElement('style');
style.textContent = '.entry-content,.wp-block-post-content{-webkit-user-select:none;user-select:none;}';
document.head.appendChild(style);
}
})();
</script>
Notes
This only deters casual copying; anything shown in a browser can still be saved. Text selection is left on by default for accessibility.
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.