सामग्री पर जाएँ
WordPress

Disable Right-Click on a WordPress Site (and What It Can’t Protect)

Hook a tiny script into wp_footer that cancels the contextmenu event. Put it in a child theme or a site-specific plugin, not the parent theme.

परखा गया WordPress 6.x

Disabling the right-click menu stops casual visitors from saving images or copying text with a click. It takes a few lines of code – but be clear about what it does and doesn’t do before you add it.

A deterrent, not protection

Anyone can still view the page source, use keyboard shortcuts, take a screenshot or switch JavaScript off. It also annoys legitimate visitors who use the menu to open links in a new tab. For images that matter, use watermarks or lower-resolution web versions.

Where to put the code

Don’t edit your theme’s functions.php directly – updates overwrite it, and many servers (including this one) disable the theme editor for security. Use a child theme or a tiny site-specific plugin:

Create this file
wp-content/plugins/disable-right-click/disable-right-click.php
disable-right-click.php
u003c?phpn/**n * Plugin Name: Disable Right-Clickn * Description: Blocks the context menu on the front end (not in wp-admin).n */nnadd_action( 'wp_footer', function () {n    if ( is_user_logged_in() ) {n        return; // Editors keep their right-click.n    }n    ?u003en    u003cscriptu003en    document.addEventListener( 'contextmenu', function ( e ) {n        if ( ! e.target.closest( 'input, textarea' ) ) {n            e.preventDefault();n        }n    } );n    u003c/scriptu003en    u003c?phpn} );
  1. Create the folder and file above (via SFTP or your host’s file manager).
  2. In WordPress go to Plugins and activate Disable Right-Click.
  3. Log out (or use a private window) and right-click the site to test.

The snippet skips logged-in users and still allows right-click inside form fields, so people can paste into your contact form.

Inder Kochar

लेखक

Inder Kochar

सिस्टम्स और नेटवर्क इंजीनियर – मैं वही समाधान लिखता हूँ जो क्लाइंट्स के साथ इस्तेमाल करता हूँ, असली सिस्टम पर परखे हुए। ऐसी ही किसी समस्या में फँसे हैं?

आगे पढ़ें

सवाल पूछें या अपना समाधान बताएँ

आपका ईमेल प्रकाशित नहीं होगा। टिप्पणियाँ जाँची जाती हैं – कृपया विषय से जुड़ी रखें।