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(){ ?>

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

<?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

13 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

  4. Elango says:

    Hi Rakesh,
    I had installed few WP plugin for the same, but I was not satisfied. Today I applied this code and working fine.

    Thank you for sharing!

    • rakesh says:

      Hi Elango, Happy to know that this method helped you to secure your code/text. Keep in touch for such wonderful ideas. :)

  5. John says:

    Hi Rakesh, thanks for sharing this tip, and i hope works on my blog.

    Because this was one of my fear to using wordpress in building my niche site since most of the guys competing with me could disable javascript, and will still copy your contents when used a plugin.

    Though, I’ve this feeling in me that this gonna work since its a Jquery snippet…

    … if that happens, i’ll still come back to give you a heads up.

    Have a great day and enjoy your weekend!

  6. Hi Rakesh,

    Right click is blocked, but text selection is still working.

    Can you help me?


    • rakesh says:

      Hi Avinash, The css code should be placed at the end of your style.css file. If your theme is overriding the old CSS then obviously it will not work.

  7. Thanks to the author for sharing such a nice content. very use full for blogger.

  8. nice article. I got the information exactly what im looking for.

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>