How to Hide View Source of Your WordPress Site
Introduction
By default, WordPress does not offer a built-in way to disable “View Source,” “Inspect,” or right-click functionality in visitors’ browsers. To add this protection layer, you can install a third-party plugin—Disable Source, Disable Right Click, and Content Protection—which blocks common ways to access your site’s HTML, CSS, and JavaScript.
Install the Plugin
- In your WordPress dashboard, go to Plugins > Add New.
- Search for Disable Source, Disable Right Click, and Content Protection.
- Click Install Now, then Activate.
Configure Protection Settings
- Navigate to Settings > Content Protection in your dashboard.
- Under General Options, enable:
- Disable Right Click
- Disable View Source / Inspect Element
- (Optional) Enable Block Keyboard Shortcuts to prevent shortcuts like Ctrl+U or Cmd+Option+U.
- Click Save Changes.
Verify the Protection
- Visit your site in an incognito/private browser window.
- Right-click anywhere on the page—context menus should be disabled.
- Attempt to use “View Page Source” (Ctrl+U/Cmd+Option+U) or open DevTools (F12)—the plugin should block these actions or redirect you.
Troubleshooting and FAQs
Q: I can still view source by disabling JavaScript—why?
A: This protection relies on JavaScript. Disabling JS in the browser bypasses it. True source hiding isn’t possible because the browser must download HTML to render the page.
Q: Some elements still show in DevTools—how can I block them?
A: Complete protection isn’t guaranteed. Consider server-side measures (e.g., obfuscating inline scripts) and ensure the plugin’s most recent version is active.
Q: Will this plugin affect site performance or SEO?
A: Minimal impact. The plugin adds a small JS script. Your content and metadata remain crawlable by search engines, as they don’t rely on client-side right-click protection.
Q: Can I customize the block message or redirect?
A: Yes—under Settings > Content Protection, you can set a custom URL or message when users attempt blocked actions.
Q: Is this a foolproof way to protect my code?
A: No. Determined users can still view source via server logs or by intercepting network traffic. This plugin deters casual copying and source viewing but doesn’t replace proper code security.