Disabling right mouse click on your website can help protect your content from being easily copied by visitors. In this post, we’ll show you how to add a small piece of code to your functions.php
file to disable right-click across your entire WordPress site.
Step-by-Step Guide:
- Access Your WordPress Dashboard
- Log in to your WordPress admin area.
- Navigate to Theme Editor
- From the dashboard, go to
Appearance
>Theme Editor
.
- From the dashboard, go to
- Open
functions.php
File- In the Theme Files section on the right, locate and click on
functions.php
. This file controls the functions of your WordPress theme.
- In the Theme Files section on the right, locate and click on
- Add the Code to Disable Right-Click
- Scroll to the bottom of the
functions.php
file and add the following code snippet:
- Scroll to the bottom of the
function disable_right_click() { echo "<script type='text/javascript'> document.addEventListener('contextmenu', function(event) { event.preventDefault(); }); </script> "; } add_action('wp_head', 'disable_right_click');
Save Your Changes
After adding the code, click the Update File button to save your changes.
Test Your Website
Visit your website and try right-clicking to ensure that the context menu is disabled.
Note: While disabling right-click can deter casual users from copying your content, it is not a foolproof method. Users with technical knowledge can still access your source code and images. Use this method as part of a broader strategy to protect your content.