Skip to contentSkip to main navigation Skip to footer

How to Customize Right Click Disable for Specific Pages

One of Hide My WP Ghost features is the ability to disable right-clicking on the frontend to prevent users from easily copying your content. However, you might want to selectively enable right-click on specific URLs. In this tutorial, we’ll show you how to customize the right-click disable feature in Hide My WP Ghost using the provided code snippet.

Before you can customize the right-click disable feature, you’ll need to access your WordPress files. You can do this via FTP or through your hosting control panel. Once you have access, locate either your theme’s functions.php file or the wp-config.php file, depending on where you want to add the customization.


Step-by-Step Guide:

Step 1: First, you need to activate Disable Right Click from Hide My WP > Tweaks > Disable Options

Step 2: Choose whether you want to add the code to your theme’s functions.php file or the wp-config.php file. Use a code editor to open the file for editing. Insert the following code:

/**
 * Deactivate disable right click on specific URLs
 * array $urls List of URLs where the right click should be 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);

        //don't activate on Home Page
        if (in_array($path, $paths)) {
            $active = false;
        }
    }

    return $active;
});

Step 3: Customize the URLs

In the code snippet, you can see an array called $urls. This array contains the URLs where you want to either enable or disable right-click. By default, the code allows right-click on the home page, ‘hello-world’, and ‘sample-page’.

You can customize this array by adding or removing URLs that match your specific requirements. Just make sure to follow the same format as the provided URLs.

Step 5: Save Your Changes

After adding the code and customizing the URLs, save the changes to the file.

Step 6: Check the Result

Now, visit the URLs you’ve customized in your browser and test the right-click functionality. It should be enabled or disabled based on your configuration.

Conclusion:

By following this tutorial and adding the provided code to your chosen file, you can selectively enable or disable right-click functionality on specific URLs, enhancing the user experience while maintaining security.

You can do the same for these HMWP hooks:

hmwp_option_hmwp_disable_inspect <- Disable Inspect Element

hmwp_option_hmwp_disable_source <- Disable View Source

hmwp_option_hmwp_disable_copy_paste <- Disable Copy Paste

hmwp_option_hmwp_disable_drag_drop <- Disable Drag-Drop Images