If you run a website, chances are you don’t want people to inspect your code, copy-paste your content, or steal your images. The browser’s Inspect Element (F12) and Right-Click menu make it very easy for users to copy content or view the source code.
That’s why many developers and website owners want to disable F12 Inspect Element, right-click, and copy-paste using JavaScript.
In this detailed guide, we’ll cover:
- Why you may want to disable right-click and F12
- How to use JavaScript snippets to block these actions
- How to add the same code in WordPress functions.php
- Best practices (and limitations) when trying to hide your website’s source code

Why Disable F12 and Right Click?
There are several reasons why website owners choose to block these actions:
- Content Protection – Prevent users from copying your text or images.
- Security Reasons – Avoid casual visitors from inspecting sensitive scripts.
- Professional Branding – Keep your code structure hidden.
- Plagiarism Prevention – Stop scrapers from stealing your work.
Important Note:
Disabling right-click or F12 does not guarantee 100% security. Advanced users can still bypass these restrictions. But it does stop the majority of casual content thieves.
Methods to Disable Right Click, F12, and Copy-Paste
There are two main methods:
- Using JavaScript in HTML files
- Adding a PHP function in WordPress (which outputs JavaScript in footer)
We’ll cover both in detail.
Method 1: Disable F12 Inspect Element and Right Click with JavaScript
The easiest way is to insert a small JavaScript snippet inside your <head> or before the </body> tag.
<script>
// Disable Right Click
document.addEventListener('contextmenu', function(event) {
event.preventDefault();
});
// Disable F12 and Ctrl+U
document.addEventListener('keydown', function(event) {
// Disable Ctrl+U
if (event.ctrlKey && (event.key === 'u' || event.key === 'U')) {
event.preventDefault();
}
// Disable F12 (Inspect Element)
if (event.keyCode === 123) {
event.preventDefault();
}
});
// Disable Text Selection (Copy-Paste)
document.addEventListener('selectstart', function(event) {
event.preventDefault();
});
</script>
Save the file and reload your webpage.
Now, users won’t be able to:
- Right-click on your page
- Press F12 to open DevTools
- Press Ctrl+U to view the source code
- Select and copy text
Method 2: Disable F12 and Right Click in WordPress (functions.php)
If you are using WordPress, you can add this function inside your functions.php file:
function disable_right_click() {
echo "
<script>
document.addEventListener('contextmenu', function(event) {
event.preventDefault();
});
document.addEventListener('keydown', function(event) {
// Disable Ctrl+U
if (event.ctrlKey && (event.key === 'u' || event.key === 'U')) {
event.preventDefault();
}
// Disable F12 (Inspect Element)
if (event.keyCode === 123) {
event.preventDefault();
}
});
document.addEventListener('selectstart', function(event) {
event.preventDefault();
});
</script>
";
}
add_action('wp_footer', 'disable_right_click');
How This Works:
- The function outputs JavaScript code in your website’s footer.
- It disables right-click, F12, Ctrl+U, and text selection.
- Works across all pages of your WordPress site.
Limitations of Disabling F12 and Right Click
Even though this method blocks most casual users, there are limitations:
- Advanced Users Can Still Bypass – Developers can disable JavaScript or use browser extensions.
- May Affect Accessibility – Users who rely on right-click for accessibility may face issues.
- Not Foolproof – Your HTML, CSS, and JS are still downloadable from server requests.
Mozilla Developer Docs on DevTools explain why blocking F12 is not always effective.
Best Practices to Protect Your Website
Instead of relying only on JavaScript tricks, combine these strategies:
- Use Watermarks on images to prevent theft.
- Implement Server-Side Protections like disabling hotlinking.
- Add DMCA Protection for your site.
- Regularly monitor plagiarism using tools like Copyscape.
- Combine right-click disable + legal measures for stronger protection.
Try our Plagiarism Checker Tool to detect stolen content.
Conclusion
Disabling F12 Inspect Element, right-click, and copy-paste using JavaScript is a quick way to protect your website from casual users trying to steal your content.
- For static sites → use the JavaScript snippet
- For WordPress → use the functions.php method
But remember — this is only a basic protection layer. Skilled users can still access your source code. For complete protection, combine it with server-side measures, DMCA protection, and watermarks.