How to Allow Right Click on Specific WordPress Pages with WP Ghost
September 11, 2023

This tutorial has moved to the new WP Ghost Knowledge Base where each feature is presented in detail.
WP Ghost’s Disable Right Click feature blocks right-clicking site-wide. Use the hmwp_option_hmwp_disable_click filter to selectively allow right-clicking on specific pages like the homepage, contact page, or any URL you choose.
When You Need Page-Level Control
WP Ghost includes a Disable Right Click feature in WP Ghost > Tweaks > Disable Options that blocks the browser context menu across your entire site. This prevents casual visitors from using “Save Image As”, “View Source”, “Inspect Element”, and other context menu actions that make it easy to copy your content.
But sometimes you need exceptions. Maybe your homepage includes an interactive element that needs the context menu. Maybe your contact page has a form that works better with right-click enabled. Or maybe you are running a documentation section where right-click is not a concern.
WP Ghost provides a filter hook that lets you allow right-clicking on specific URLs while keeping it disabled everywhere else. The same approach works for Disable Inspect Element, Disable View Source, Disable Copy/Paste, and Disable Drag/Drop.
Step 1 – Enable Disable Right Click in WP Ghost
Before you can create exceptions, the feature needs to be active.
1. Go to WP Ghost > Tweaks > Disable Options.
2. Switch on Disable Right Click.
3. Click Save.

Right-clicking is now disabled on every page of your site for all visitors.
Step 2 – Add the Exception Code
Open your theme’s functions.php file or your wp-config.php file using sFTP, File Manager, or the WordPress theme editor. Add the following code:
/**
* Allow right click on specific URLs
* array $urls List of URLs where right click should remain active
*/
add_filter('hmwp_option_hmwp_disable_click', function($active){
if(isset($_SERVER['REQUEST_URI'])) {
$urls = array(
home_url(), //home page
home_url('hello-world'),
home_url('sample-page'),
);
$path = rtrim($_SERVER['REQUEST_URI'], '/') . '/';
$paths = array_map(function ($url){
return trailingslashit(parse_url($url, PHP_URL_PATH));
}, $urls);
if (in_array($path, $paths)) {
$active = false;
}
}
return $active;
});Step 3 – Customize the URL List
Edit the $urls array to include the pages where you want right-click to be allowed. Replace the example URLs with your actual page URLs:
$urls = array(
home_url(), // homepage
home_url('contact'), // contact page
home_url('documentation'), // documentation section
home_url('shop/my-product'), // specific product page
);Use home_url() for the homepage and home_url('your-page-slug') for any other page. The slug is the part of the URL after your domain name.
Step 4 – Save and Test
Save the file and visit the pages you configured. Right-clicking should work on the pages in your list and remain disabled on all other pages.

Same Approach for Other Disable Options
The same filter pattern works for all five Disable Options in WP Ghost. Just replace the filter name in the code:
hmwp_option_hmwp_disable_click – controls Disable Right Click. Use this to allow right-clicking on specific pages.
hmwp_option_hmwp_disable_inspect – controls Disable Inspect Element. Use this to allow DevTools shortcuts on specific pages.
hmwp_option_hmwp_disable_source – controls Disable View Source. Use this to allow Ctrl+U on specific pages.
hmwp_option_hmwp_disable_copy_paste – controls Disable Copy/Paste. Use this to allow text selection and copying on specific pages.
hmwp_option_hmwp_disable_drag_drop – controls Disable Drag/Drop. Use this to allow image dragging on specific pages.
For example, to allow Inspect Element on your documentation pages while keeping it disabled everywhere else, use the same code but change the filter name to hmwp_option_hmwp_disable_inspect.
You can also combine multiple filters in the same code block to control different features on different pages. For the complete reference of all WP Ghost hooks, see the developer documentation.
Frequently Asked Questions
Can I allow right-click for logged-in users instead of specific pages?
Yes. WP Ghost already includes a built-in option for this. In WP Ghost > Tweaks > Disable Options, you will find a Disable Right Click for Logged Users toggle with user role selection. If you only want to disable right-click for non-logged-in visitors, leave this toggle off. No custom code needed.
Should I add the code to functions.php or wp-config.php?
Both work. Adding it to functions.php is the standard WordPress approach for filters, but the code will be lost if you change themes. Adding it to wp-config.php persists across theme changes. For a permanent solution that survives theme updates, wp-config.php or a site-specific custom plugin is recommended.
Will this stop determined users from copying my content?
Disabling right-click and related features blocks casual copying. It stops the majority of visitors who rely on the browser’s built-in tools. It will not stop a determined developer who uses external tools, browser extensions, or the terminal. Think of it as a practical barrier that protects against casual content theft, not an absolute lock.
Does this affect mobile users?
Yes. On mobile devices, the disable features block the long-press context menu (which is the mobile equivalent of right-click), text selection, and image saving. The page-level exceptions work on mobile too.
Does WP Ghost modify WordPress core files?
No. WP Ghost uses server rewrite rules and WordPress hooks. No core files are moved, renamed, or modified. Deactivating the plugin restores all default behavior instantly.