How to disable right click and Text Selection in WordPress


It is very common to watch that some bloody spammer keep on copy pasting your important article on their website and, Since your countries cyber Law is not applicable on them.  These spammers even does not care to change your links.

They simply copy paste your article, to disable right click and selection of your text, there are WordPress plugin but as, We hate adding every next Plugin, We love to hack the system.  Here is my hack to do this.

Open your functions.php file and add the following code in it. This will prevent right click on your website. ( Here we are assuming that you are loading jquery as per the requirement)


function disable_right_click(){ ?>

<script>
//// Disable right click
jQuery(document).bind('contextmenu', function (e) {
e.preventDefault();
// alert('Right Click is not allowed');
});
</script>

<?php }

add_action( 'wp_footer', 'disable_right_click' );

Now its time to disable selection of text using mouse or keyboard. The trick is very simple, again open your style.css file and copy paste the following code.


body {
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
user-select: none; }

Now save your work and enjoy.




Suggested Similar Articles

6 Brilliant Comments - Join Discussion Now!

  1. Good tip Rakesh bro.

    There are many guys looking out for this information. They end up using plugin for the same, and you have given us the code that is much better than using an extra theme.

    Thanks for this bro.

    • rakesh says:

      Hi Atish, Since I always hate to add plugin as we do not know how they have been coded and sometimes a cheaply coded plugin increase the loading time instead of enhancing the output.

      Keep in touch :)

  2. Shameem says:

    Hi Rakesh Ji

    Its good method to protect our content from thieves which I’ve used plugin in my blog by using coded will help to reduce the plugins count thanks for sharing this methods.

    • rakesh says:

      Hi Shameem, Good to know that you like these tricks to protect your contents. Keep in touch for such tricks and tips.

  3. Thanks Bro to telling easy method of disabling right click. I am using this method for saving my content.

    • rakesh says:

      Hi Pankaj, Very happy to know that a lots of people are now using this small yet useful method to protect their contents. keep in touch

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>