Zum Inhalt springen
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.

Getestet mit 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

Geschrieben von

Inder Kochar

System- & Netzwerkingenieur – Ich schreibe die Lösungen auf, die ich bei Kunden einsetze – getestet auf echten Systemen. Hängen Sie an etwas Ähnlichem fest?

Weiterlesen

Stellen Sie eine Frage oder teilen Sie Ihre Lösung

Ihre E-Mail-Adresse wird nicht veröffentlicht. Kommentare werden moderiert – bitte beim Thema bleiben.