×

How to disable right click and Text Selection in WordPress

default single post image

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)

[code]

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’ );

[/code]

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.

[code]

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

[/code]

Now save your work and enjoy.

Related Posts

One thought on “How to disable right click and Text Selection in WordPress”

  1. Hi, thanks for sharing this article, i just wanted to ask you one thing that if i want this only on posts single.php page what to do then, i don’t want this on my whole website.. i want this only on my posts single page.. please help me out..

Leave a Reply

Your email address will not be published.