Disable right click in wordpress disallow users with various options, including the ability to save images, copy text, and inspect elements. By disabling this functionality, website owners aim to deter users from easily copying and downloading their content.
In this article, we’ll guide you through the process of disabling right-click in WordPress without the use of plugins.
Why we should disable right click in wordpress website
Content Protection:
Disable right-click in wordpress can deter casual users from easily copying and saving images or text from your website.
Preventing Image Theft:
Photographers, artists, or anyone with visual content may use this method to make it more difficult for users to save or download their images.
Please note the following considerations:
Backup:
Before making any changes to theme files, it’s advisable to create a backup of your website. This ensures you can revert to the previous state if anything goes wrong.
Child Theme:
If you’re working with a custom theme, it’s often recommended to use a child theme to make modifications. This prevents your changes from being overwritten during theme updates.
Syntax Check:
Ensure that the code you add is correct and follows PHP syntax. A small mistake in the functions.php file can break your entire site.
Remember that modifying theme files directly should be done carefully, and it’s always good practice to have a development or staging environment for testing before applying changes to a live site.
Step-by-Step Guide:
Accessing Theme Files:
In the Theme Editor, look for the functions.php file on the right-hand side. It’s usually found under the “Theme Files” section in your wordpress dashboard.
Update the following code in theme file:
if ( !is_user_logged_in() ) {
function disable_right_click_idc() {
?>
<script>
document.addEventListener("contextmenu", function(e) {
e.preventDefault();
}, false);
</script>
<?php
}
add_action('wp_footer', 'disable_right_click_idc');
}
After inserting the code, click the “Update File” button to save your changes.